Showing posts with label problem. Show all posts
Showing posts with label problem. Show all posts

Saturday, August 9, 2014

Pascal's Triangle Program

This is Pascal's triangle program. Was probably one of the hardest programs I had during my second year. But looking back, its not as hard as it seems. For those who have trouble with this program, I suggest you to write it down, step by step with pencil and paper to see how the program works. If you need help, feel free to ask.

#include<stdio.h>
main()
{
int d,i,j,n,a[50],k,b[50];
printf("enter limit");
scanf("%d",&n);
d=n;
for(i=0;i<n;i++)
{
a[0]=1;
a[i]=1;
for(j=1;j<i;j++)
{
a[j]=b[j-1]+b[j];
}
for(k=0;k<(d-1);k++)
{
printf(" ");
}
d--;
for(k=0;k<=i;k++)
{
printf("%d",a[k]);
printf(" ");
}
for(k=0;k<=i;k++)
printf("\n");
for(k=0;k<=i;k++)
b[k]=a[k];
}
}