-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_X.c
50 lines (45 loc) · 874 Bytes
/
print_X.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
// Write a C program to print out an X shape of size and width n
// eg.
//
// X X X X X X X X
// X XX X X X X
// X X XX X X X
// n=3 X X X X X X
// n=4 X X X
// n=5 X X
// X X
// X X
// X X
// n=9
//
#include <stdio.h>
void print_x(int n)
{
int i = n;
int j;
while (i > 0) {
j = n;
while (j > 0) {
if ((j == i) || j == ((n - i) + 1)) {
printf("x");
} else {
printf(" ");
}
j--;
}
printf("\n");
i--;
}
}
int main()
{
print_x(3);
printf("\n");
print_x(4);
printf("\n");
print_x(5);
printf("\n");
print_x(9);
printf("\n");
return 0;
}