-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path15.c
More file actions
36 lines (34 loc) · 670 Bytes
/
Copy path15.c
File metadata and controls
36 lines (34 loc) · 670 Bytes
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
// Given a string
// ```
// char str [ ] = “123456789” ;
// ```
// Write a program that displays the following:
// ```
// 1
// 2 3 2
// 3 4 5 4 3
// 4 5 6 7 6 5 4
// 5 6 7 8 9 8 7 6 5
// ```
#include <stdio.h>
int main()
{
char str[] = "123456789";
int n = 5;
for (int i = 0; i < n; i++)
{
for (int j = n-i; j > 0; j--)
{
printf(" ");
}
for (int j = i+1; j < 2*i+2; j++)
{
printf("%c ", str[j-1]);
}
for (int j = 2*i; j > i; j--)
{
printf("%c ", str[j-1]);
}
printf("\n");
}
}