pAlindrome

huh .. ada tugas kuliah disuruh bikin program yang bisa menampilkan palindrome angaka, segitiga pascal…

Pascal Triangle In C


Code:

        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321

Code:

#include<stdio.h>
#include<stdlib.h>

void piramid(int const c)
{
    int x,y;
    for(y=0; y<c; y++)
    {
        for(x=0; x<c-(1+y)+((y*2)+1); x++)
        {
            if(x<(c-(y+1)))printf(" ");
            else
            {
                if(x-(c-(y+2))>y+1) printf("%d",(2*y)+2-(x-(c-(y+2)) ));
                else printf("%d",(x-(c-(y+1))+1 ));
            }
        }
        printf("\n");
    }
}

int main(int argc, char* argv[])
{
    if (argc==2)
    {

        if (atoi(argv[1])>9 || atoi(argv[1])<=1)
        {
            printf("Insert range within 2 to 9, ig. %s 9n",argv[0]);
            return 1;
        }
        piramid(atoi(argv[1]));
    }
    else
        printf("Insert range within 2 to 9, ig. %s 9n",argv[0]);
    return 0;
}

ref: http://cc.byexamples.com/20070529/pa…gle-challenge/

nyoba aku porting ke console c sharp menjadi :

Code:

int x,y,c=5;
    for(y=0; y<c; y++)
    {
        for(x=0; x<c-(1+y)+((y*2)+1); x++)
        {
            if(x<(c-(y+1)))Console.Write(" ");
            else
            {
                if(x-(c-(y+2))>y+1) Console.Write("{0}",(2*y)+2-(x-(c-(y+2)) ));
                else Console.Write("{0}",(x-(c-(y+1))+1 ));
            }
        }
Console.WriteLine;
    }

dapet tugas kuliah bikin

segitiga triangle berbentuk wajik.. aku pakai c sharp dan menggunakan array, iseng pakai cara sendiri..

toolbox menggunakan 1 button dan texboxt propertinya aku bikin mutiline , align text center

Code:

int a, b, c = 6, f;
            string d = "1";
            int[] arr = new int[10];
            for (a = 1; a < c; a++)
            {

                textBox1.Text += Environment.NewLine;
                f = Convert.ToInt32(d);
                arr[a] = f * f;
                textBox1.Text += string.Format("{0}", f * f);
                d += 1;
                if (a == 5)
                {

                    for (b = 4; b >= 1; b--)

                        textBox1.Text += Environment.NewLine + string.Format("{0}", arr[b]);

 


About this entry