-
Notifications
You must be signed in to change notification settings - Fork 0
/
75_pascal_triangle.c
51 lines (50 loc) · 1.12 KB
/
75_pascal_triangle.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
#include <stdio.h>
int fact(int);
int combi(int, int);
void printPascal(int);
int fact(int n)
{
int f = 1;
while (n >= 1)
{
f = f * n;
n--;
}
return (f);
}
int combi(int n, int r)
{
return (fact(n) / fact(n - r) / fact(r));
}
void printPascal(int line)
{
int i, j, k, r;
for (i = 1; i <= line; i++)
{
k = 1;
r = 0;
for (j = 1; j <= 2 * line - 1; j++)
{
if (j >= line + 1 - i && j <= line - 1 + i && k)
{
printf("%2d", combi(i - 1, r));
k = 0;
r++;
}
else
{
printf(" ");
k = 1;
}
}
printf("\n");
}
}
int main()
{
int a;
printf("Enter no of rows ");
scanf("%d", &a);
printPascal(a);
return 0;
}