// c code to generate pascal triangle
#include<stdio.h>
#include<conio.h>
int main(){
clrscr();
int r,row,s,n,binom;
printf("enter number of rows in pascal triangle:\n");
scanf("%d",&row);
for(r=0;r<row;r++){
for(s=40-3*r;s>0;s--)
printf(" ");
for(n=0;n<=r;n++){
if(n==0 || r==n)
binom=1;
else
binom=binom*(r-n+1)/n;
printf("%6d",binom);
}
printf("\n");
}
getch();
return 0;
}
No comments:
Post a Comment