forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pascal.cpp
45 lines (34 loc) · 888 Bytes
/
Pascal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* C program to print Pascal triangle up to n rows */
#include <stdio.h>
long long fact(int n); // Function definition
int main()
{
int n, k, rows, i; //Declare variables
long long term;
printf("Enter number of rows : ");
scanf("%d", &rows); //Initialize the rows
printf("\n");
for(n=0; n<rows; n++)
{
for(i=n; i<=rows; i++) //Print 3 spaces
printf("%3c", ' ');
for(k=0; k<=n; k++) //Term for the rows
{
term = fact(n) / (fact(k) * fact(n-k)); //Function Call
printf("%6lld", term); //Print the terms
}
printf("\n");
}
return 0;
}
/* Function to calculate factorial */
long long fact(int n) //Function Definition
{
long long factorial = 1ll;
while(n>=1)
{
factorial *= n;
n--;
}
return factorial;
}