#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int main(void)
{
int arr[10][10];
int i, j, k;
clrscr();
printf("\nProgram for printing Pascal's Triangle:\n\n\n");
for(i=0; i<10; i++)
{
j=1;
arr[i][0]=1;
arr[i][i]=1;
while( j< i) {
arr[i][j]=arr[i-1][ j-1]+arr[i-1][ j];
j++; }
}
for(i=0;i <10;i++) //display part
{
j=10;
while( j>i) { printf(" "); //mention 2 spaces betw the double quotes
j--;
}
for(k=0;k<=i;k++)
{
printf("%4d",arr[i][k]);
}
printf("\n\n");
} //display for loop close
getch();
return 0;
} //main close
No comments:
Post a Comment