forked from rachitsainii/cpp-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpascals_traingle.c
52 lines (45 loc) · 861 Bytes
/
pascals_traingle.c
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
46
47
48
49
50
51
52
#include <stdio.h>
long long fact(long long num)
{
long long factorial=1;
while(num>0)
{
factorial=factorial*num;
num--;
}
if (num==0)
{
return factorial;
}
}
long long combination(long long n, long long r)
{
long long c;
c=fact(n)/(fact(r)*fact(n-r));
return c;
}
void main()
{
int lines;
printf("Enter number of lines in the triangle: ");
scanf("%d", &lines);
for (int i = 0; i <= lines; i++)
{
printf(" ");
}
if (lines>=1) printf(" 1\n");
for (int i = 1; i < lines; i++)
{
long temp=0;
for (int s = 0; s < lines-i; s++)
{
printf(" ");
}
while (temp <= i)
{
printf("% 4lld", combination(i,temp));
temp++;
}
printf("\n");
}
}