Home / Programs / C program to print hollow rhombus, parallelogram star pattern ***** * * * * * * *****
Programming Example

C program to print hollow rhombus, parallelogram star pattern
    *****
   *   *
  *   *
 *   *
*****

👁 1,483 Views
💻 Practical Program
📘 Step by Step Learning
Write a C program to print hollow rhombus star series pattern using for loop. How to print hollow rhombus or parallelogram star pattern in C programming. Logic to print empty rhombus or parallelogram star pattern series in C programming.

Program Code

/**
 * 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

Output

Enter rows: 5
    *****
   *   *
  *   *
 *   *
*****

Explanation

Logic to print hollow rhombus star pattern

 

    *****
   *   *
  *   *
 *   *
*****

 

Step by step descriptive logic to print rhombus star pattern.

  1. Input number of rows to print from user. Store it in a variable say rows.
  2. To iterate through rows, run an outer loop from 1 to rows. Define an outer loop with structure for(i=1; i<=rows; i++).
  3. To print trailing spaces, run an inner loop from 1 to rows - i. Run a loop with structure for(j=1; j<=rows - i; j++). Inside this loop print blank space.
  4. To print stars, run another inner loop from 1 to rows with structure for(j=1; j<=rows; j++).
  5. Inside this loop print star for first or last row, and for first or last column otherwise print spaces. Which is print stars only when i==1 or i==rows or j==1 or j==rows.
  6. After printing all columns of a row move to next line i.e. print new line.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.