Sunday, June 26, 2011

C Programming - Program Membuat Segitiga Pascal


#include <stdio.h>

int bil, a, i, j, k;
int main()
{
    int pascal(int);
    printf("Masukkan sebuah nilai: ");
    scanf("%d", &amp;bil);
    for (i=0; i&lt;=bil; i++)
    {
        for (k=0; k&lt;=((2*bil)-(2*i)); k++)
        {
            printf(" ");
        }
        for (j=0; j&lt;=i; j++)
        {
            pascal(j);
        }
        printf("\n");
    }
    return 0;
}

int pascal(j)
{
    if (j==0||i==j)
    {
        a=1;
    }
    else
    {
        a=a*(i+1-j)/j;
    }
    printf("%4i", a);
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...