Friday, July 3, 2015

Pascal triangle

#include<stdio.h>

///pascal triangle

int fact(int num);

int main()
{
    int row,i,j;

    printf("Enter the no. of rows:");

    scanf("%d",&row);

    for(i=0; i<row; i++)
    {

        for(j=0; j<row-i-1; j++)

            printf(" ");

        for(j=0; j<=i; j++)

            printf("%d ",fact(i)/(fact(j)*fact(i-j)));

        printf("\n");
    }
    return 0;
}

int fact(int num)
{
    int fact=1;
    int i;
    for(i=1; i<=num;i++)
    {
        fact=fact*i;
    }
    return fact;
}






output:







                                         
                             

No comments:

Post a Comment