-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMirror_Number_Pyramid.c
53 lines (37 loc) · 1.03 KB
/
Mirror_Number_Pyramid.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
53
// Mirror Number Pyramid
#include <stdio.h>
int main()
{
int n; // Number of lines
printf("Enter no of lines: ");
scanf(“%d”, &n);
int n_space = n-1; // No of space
for (int i = 1; i <= n; i++){ //outer loop for row
for (int s = 1; s <= n_space; s++) { // inner loop for col to print space brfore element
printf(" "); // print double space due to duble digit
}
n_space--;
for(int j = 1; j <= i; j++){ //nested loop for col to print no triangle
printf("%d",j);
printf(" ");
}
int a = i-1; // extra variable
for(int k = 1; k <= i-1; k++){ //nested loop for col to print extra no
printf("%d",a);
printf(" ");
a--;
}
printf("\n");
}
return 0;
}
/*
=== Code Execution Successful ===
Enter no of lines: 5
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
=== Code Execution Successful ===
*/