*****
* *
* *
* *
*****
/**
* C program to print hollow rhombus star pattern
* atnyla.com
*/
#include <stdio.h>
int main()
{
int i, j, rows;
/* Input number of rows from user */
printf("Enter rows : ");
scanf("%d", &rows);
for(i=1; i<=rows; i++)
{
/* Print trailing spaces */
for(j=1; j<=rows-i; j++)
{
printf(" ");
}
/* Print stars and center spaces */
for(j=1; j<=rows; j++)
{
if(i==1 || i==rows || j==1 || j==rows)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
Enter rows: 5
*****
* *
* *
* *
*****
***** * * * * * * *****
Step by step descriptive logic to print rhombus star pattern.
for(i=1; i<=rows; i++).rows - i. Run a loop with structure for(j=1; j<=rows - i; j++). Inside this loop print blank space.for(j=1; j<=rows; j++).i==1 or i==rows or j==1 or j==rows.First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.