0
2.3kviews
Write a program to generate Pascal triangle upto n rows.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 10 M

Year: May 2016

1 Answer
0
25views
#include<stdio.h>
main()
{
int n,i,j,k,coef;
printf(“Enter number of rows:”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n-i;j++)
    {
    printf(“  ”);
}
for(k=1;k<=i;k++)
{
    if(k==1 || k==i)
    coef=1;
    else
    coef=coef*(i-j+1)/(j-1);

    printf(“%d”,coef);
}
    printf(“\n”);
}
}




Output:
                1
               1 1
              1 2 1
             1 3 3 1
            1 4 6 4 1
Please log in to add an answer.