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

C Programming Language Loop control in C Language (Article) Loop control in C Language (Program)

1362

Program:

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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.