Signup/Sign In

C Program To Print Hollow Diamond Star Pattern

The Hollow Diamond Pattern is similar to the pyramid pattern program, In Hollow Diamond Star Program it is divided into two parts upper and lower, the upper part is similar to the pyramid pattern and the lower part is an inverted pyramid, the major difference is only one star in the first row and last row and other rows have almost two stars.

Algorithm To Print Hollow Diamond Star Pattern:

  • Get the input from the user to print the Hollow Diamond
  • The Hallow Diamond Pattern is similar to the pyramid pattern
  • The only difference is we replace the * characters with spaces
  • The Hallow Diamond Pattern consists of 1 star in the first row and last row
  • except for the first and last row, every row has 2 stars.
  • The lower part of the Hallow Diamond is an inverted triangle

The below program is similar to the diamond star pattern program, Only the difference is here all the special characters in between the first and last character of rows are replaced with Spaces.

C Program To Print Hollow Diamond Star Pattern:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,j,rows;
printf("Enter the number of rows to print the Hallow Diamond: \n");
scanf("%d",&rows);//get input from user

//Code Block To Print Upper Diamond

for(i=1; i<=rows; i++){
for(j=rows; j>i; j--){
printf(" ");
}
printf("*");
for(j=1; j<(i-1)*2; j++){
printf(" ");
}
if(i==1){
printf("\n");
}
else{
printf("*\n");
}
}

//Code Block To Print Lower Diamond
for(i=rows-1; i>=1; i--){
for(j=rows; j>i; j--){
printf(" ");
}
printf("*");
for(j=1; j<(i-1)*2; j++){
printf(" ");
}
if(i==1){
printf("\n");
}
else{
printf("*\n");
}
}

return 0;
}

Output:

C program to print Hollow Diamond Star Pattern



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight