Pascal Triangle
#include <stdio.h>
int main() {
int rows, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i=0;i<rows;i++){
for (j=0;j<rows-i-1;j++) {
printf(" ");
}
int val = 1;
for (j=0;j<=i;j++) {
printf("%4d",val);
val = val * (i - j) / (j + 1);
}
printf("\n");
}
return 0;
}
Enter the number of rows: 5
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Comments
Post a Comment