From d122623b5715400c8c8dd4f48c07f108634b4855 Mon Sep 17 00:00:00 2001 From: srinidhigopalan <114827080+srinidhigopalan@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:43:51 +0530 Subject: [PATCH] chore(C): Added pascals triangle code --- algorithms/C/maths/pascals-triangle.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 algorithms/C/maths/pascals-triangle.c diff --git a/algorithms/C/maths/pascals-triangle.c b/algorithms/C/maths/pascals-triangle.c new file mode 100644 index 00000000..9fecb4b2 --- /dev/null +++ b/algorithms/C/maths/pascals-triangle.c @@ -0,0 +1,21 @@ + +#include +long factorial(int); +int main() +{ + int i, n, c; + printf("Enter the number of rows you wish to see in pascal triangle\n"); + scanf("%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"); + } + return 0; +} +long factorial(int n) { + int c; + long result = 1; + for (c = 1; c <= n; c++) result = result * c; + return result; +} \ No newline at end of file