forked from dimpeshmalviya/C-Language-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhexagon.c
More file actions
31 lines (27 loc) · 630 Bytes
/
hexagon.c
File metadata and controls
31 lines (27 loc) · 630 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
#include <stdio.h>
int main() {
int n, i, j;
printf("Enter size of hexagon (e.g. 4 or 5): ");
scanf("%d", &n);
// Upper part
for (i = 0; i < n; i++) {
// spaces
for (j = 0; j < n - i - 1; j++)
printf(" ");
// stars
for (j = 0; j < n + 2 * i; j++)
printf("*");
printf("\n");
}
// Lower part
for (i = n - 2; i >= 0; i--) {
// spaces
for (j = 0; j < n - i - 1; j++)
printf(" ");
// stars
for (j = 0; j < n + 2 * i; j++)
printf("*");
printf("\n");
}
return 0;
}