-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHollow-Diamond.c
55 lines (50 loc) · 915 Bytes
/
Hollow-Diamond.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
54
55
/*
Program to print a hollow diamond.
*/
#include <stdio.h>
int main()
{
int r;
printf("Enter value of n(integer only): ");
scanf("%d",&r);
r = (2*r) + 1; //2n+1 rows
for (int i=0;i<r;i++)
{
for (int j=0;j<r;j++)
{
if (i+j==((r-1)/2) || (i-j==((r-1)/2)) || (j-i==((r-1)/2)) || ((i+j==((3*r-3)/2) && i>((r-1)/2))))
{
printf("*");
}
else
printf(" ");
}
printf("\n");
}
}
/*
Input:
Enter value of n(integer only): 10
Output:
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/