-
Notifications
You must be signed in to change notification settings - Fork 765
/
Copy pathhollow diamond
43 lines (39 loc) · 900 Bytes
/
hollow diamond
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
#include <stdio.h>
int main()
{
int i, j, n;
scanf("%d", &n);
// first half
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i + j <= n - 1) // upper left triangle
printf("*");
else
printf(" ");
if((i + n) <= j) // upper right triangle
printf("*");
else
printf(" ");
}
printf("\n");
}
// second half
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i >= j) //bottom left triangle
printf("*");
else
printf(" ");
if(i >= (2 * n - 1) - j) // bottom right triangle
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}