#include<stdio.h>
#include<conio.h>
main()
{
int i,j,z,k;float h=1;
printf("enter the level upto which u wish to print the pascal triangle");
scanf("%d",&z);--z;
for(i=0;i<=z;i++)
{
for(j=1;j<=z-i;j++)
{printf(" ");} // to prrovide space to obtain triangular shape
for(j=0;j<=i;j++)
{
for(k=0;k<=j-1;k++)
{
h*=(i-k)/(j-k);
} //to print the binomial coefficients....
k=h;
printf("%d ",k);
h=1;
}printf("\n");//to begin from another line of the program..
}
getch();
}
My concern is that the triple loop in the program makes it complex.....is there a simpler alternative......please suggest.......
the output shud be like
Yes you can do it in with 2 for statements. I had to do this for homework, it sucked.
Actually i'm not sure because mine isn't printed out as a triangle.
I had a for loop for the rows, and a for loop for the columns. I had it so that the loop for run like this: row 1 col 1, row 2 col1 col 2, row 3 col 1 col 2 col 3, row 4 col 1 col 2 col 3 col 4...etc. For each new row I had the value reset back to 1. Now all you have to do is find the pattern that will solve each individual number.