-
Notifications
You must be signed in to change notification settings - Fork 16
/
4.c
44 lines (39 loc) · 823 Bytes
/
4.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
#include<stdio.h>
int main()
{
int n;
printf("How many numbers: ");
scanf("%d", &n);
int pascal[n][n];
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
pascal[i][j] = 0;
}
}
for (int i=0; i<n; i++)
{
for (int j=0; j<i; j++)
{
if (j == 0 || j == i)
pascal[i][j] = 1;
else
pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j];
}
}
int count = 0;
for (int i=0; i<n; i++)
{
for (int j=0; j<i; j++)
{
if (pascal[i][j] != 0)
{
printf("%d ", pascal[i][j]);
count += pascal[i][j];
}
}
printf("\n");
}
printf("Total number of elements: %d\n", count);
}