📚Intermediate

Print Hollow Star Pyramid in Diamond Shape

Print hollow diamond pattern

Print a hollow diamond shape pattern with stars only on the boundary.

C Program to Print Hollow Diamond Pattern

hollow_diamond.c
C
1#include <stdio.h>
2
3int main() {
4 int rows;
5
6 printf("Enter number of rows: ");
7 scanf("%d", &rows);
8
9 printf("\n");
10
11 // Upper half
12 for (int i = 1; i <= rows; i++) {
13 // Leading spaces
14 for (int j = 1; j <= rows - i; j++) {
15 printf(" ");
16 }
17
18 // Stars and hollow
19 for (int j = 1; j <= 2 * i - 1; j++) {
20 if (j == 1 || j == 2 * i - 1) {
21 printf("*");
22 } else {
23 printf(" ");
24 }
25 }
26 printf("\n");
27 }
28
29 // Lower half
30 for (int i = rows - 1; i >= 1; i--) {
31 // Leading spaces
32 for (int j = 1; j <= rows - i; j++) {
33 printf(" ");
34 }
35
36 // Stars and hollow
37 for (int j = 1; j <= 2 * i - 1; j++) {
38 if (j == 1 || j == 2 * i - 1) {
39 printf("*");
40 } else {
41 printf(" ");
42 }
43 }
44 printf("\n");
45 }
46
47 return 0;
48}
Output

Enter number of rows: 5

 

*

* *

* *

* *

* *

* *

* *

* *

*

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples