Maaf, Anda mengaktifkan Adblock pada browser anda!
Atau anda tidak mengaktifkan Javascript![ Disable Your AdBlock Please ]
Home > Algoritma dan Pemrograman > Pascal Triangle Algorithm example in C programming

Pascal Triangle Algorithm example in C programming

Pascal Triangle Algorithm

Pascal Triangle Algorithm example in C programming :



#include <stdio.h>

long fact(int);
int main() {
int line, i, j;
printf("Enter the no. of lines: ");
scanf("%d", &line);
for (i = 0; i < line; i++) {
for (j = 0; j < line - i - 1; j++){
printf(" ");
}
for (j = 0; j <= i; j++){
printf("%ld ", fact(i) / (fact(j) * fact(i - j)));
}
printf("n");
}
return 0;
}
long fact(int num) {
long f = 1;
int i = 1;
while (i <= num) {
f = f * i;
i++;
}
return f;
}


OUTPUT

Enter the no. of lines: 4
1
1 1
1 2 1
1 3 3 1

Leave a Reply

Your email address will not be published. Required fields are marked *

*