Created
December 31, 2017 03:58
-
-
Save winhtut/854e46fb0d2696ff8a7d18efb0ca054c to your computer and use it in GitHub Desktop.
Pascal Triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include<conio.h> | |
long factorial(int); | |
int main() | |
{ | |
int i, n, c; | |
printf("Enter the number of rows you wish to see in pascal triangle\n"); | |
scanf_s("%d", &n); | |
for (i = 0; i < n; i++) | |
{ | |
for (c = 0; c <= (n - i - 2); c++) | |
printf(" "); | |
for (c = 0; c <= i; c++) | |
printf("%ld ", factorial(i) / (factorial(c)*factorial(i - c))); | |
printf("\n"); | |
} | |
_getch(); | |
return 0; | |
} | |
long factorial(int n) | |
{ | |
int c; | |
long result = 1; | |
for (c = 1; c <= n; c++) | |
result = result*c; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment