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 in C program. Logic to print mirrored rhombus or parallelogram star pattern series in C programming.
Required knowledge
Basic C programming, For loop, Nested loop
Logic to print mirrored rhombus star pattern
Read more – Program to print rhombus star pattern series
The above pattern contains N rows and each row contains N columns (where N is total rows to be print). If you have noticed there are i - 1
spaces per row (where i is 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 to print mirrored rhombus star pattern.
- Input number of rows to print from user. Store it in a variable say N.
- To iterate through rows, run an outer loop from 1 to N, increment 1 in each iteration. The loop structure should look like
for(i=1; i<=N; i++)
. - To print spaces, run an inner loop from 1 to
i - 1
with structurefor(j=1; j<i; j++)
. Inside this loop print single blank space. - To print stars, run another inner loop from 1 to N with structure
for(j=1; j<=N; j++)
. Inside this loop print star. - After printing all columns of a row, move to next line i.e. print new line.
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
Logic to print mirrored parallelogram star pattern is same as of mirrored rhombus star pattern. The only change we need to make is we need to iterate though M rows and N columns (where M is the total number of rows to print and N is total number of columns to print).
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 😉
Recommended posts
- Star patterns programming exercises index.
- Number pattern programming exercises index.
- Loop programming exercises index.
- Recommended patterns –
***** ***** ***** ***** *****
***** * * * * * * *****
***** ***** ***** ***** *****
***** * * * * * * *****
***** * * * * * * *****