C program to print mirrored rhombus, parallelogram star pattern

Write a C program to print inverted/mirrored rhombus star pattern series using for loop. How to print inverted/mirrored rhombus or parallelogram star pattern of N rows using for loop in C programming. Logic to print mirrored rhombus or parallelogram star pattern series using loop in C program.

Example

Input

Input rows: 5

Output

Required knowledge

Basic C programming, For loop

Logic to print mirrored rhombus star pattern

Read more - Program to print rhombus star pattern series

Talking about this pattern, it contains N rows and each row contains exactly N columns (where N is the total rows to be printed). If you have noticed there are i - 1 spaces per row (where i is the current row number). You can hover or click on to the above pattern to see or count total spaces per row.

Step-by-step descriptive logic:

  1. To iterate through rows, run an outer loop from 1 to N (where N is the total number of rows).
  2. To print spaces, run an inner loop from 1 to i - 1 (where i is the current row number). Inside this loop print single blank space.
  3. To iterate though columns and print stars, run another inner loop from 1 to N. Inside this loop print star(*) or any other character which you want to get printed as output.

Program to print mirrored rhombus star pattern

/*
 * C program to print mirrored Rhombus star pattern series
 */

#include <stdio.h>

int main()
{
    int i, j, N;

    // Input number of rows from user
    printf("Enter rows: ");
    scanf("%d", &N);


    for(i=1; i<=N; i++)
    {
        // Print trailing spaces 
        for(j=1; j<i; j++)
        {
            printf(" ");
        }

        for(j=1; j<=N; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

Output

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

Logic to print mirrored parallelogram star pattern

Entire logic to print mirrored parallelogram star pattern will be same as of mirrored rhombus star pattern which we just printed. The only change we need to do with this pattern is we need to iterate though M rows and N columns (where M is the total number of rows to be printed and N is total number of columns to be printed). Rest of the things would be same as of first pattern we did.

Program to print mirrored parallelogram star pattern

/*
 * C program to print mirrored parallelogram star pattern series
 */

#include <stdio.h>

int main()
{
    int i, j, M, N;

    // Input number of rows and columns
    printf("Enter rows: ");
    scanf("%d", &M);
    printf("Enter columns: ");
    scanf("%d", &N);


    for(i=1; i<=M; i++)
    {
        // Print trailing spaces
        for(j=1; j<i; j++)
        {
            printf(" ");
        }

        for(j=1; j<=N; j++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>