Example:
Input rows: 5
Input columns: 20
Output:
***** ***** ***** ***** *****
******************** ******************** ******************** ******************** ********************
Required knowledge
Basic C programming, For loopLogic to print mirrored rhombus star pattern
Before moving on to this pattern you might want to learn logic of printing rhombus star pattern as it is similar to mirrored rhombus star pattern.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:
- To iterate through rows, run an outer loop from 1 to N (where N is the total number of rows).
- 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.
- 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; //Reads number of rows from user printf("Enter rows: "); scanf("%d", &N); for(i=1; i<=N; i++) { //Prints trailing spaces for(j=1; j<i; j++) { printf(" "); } for(j=1; j<=N; j++) { printf("*"); } printf("\n"); } return 0; }
Output
Enter rows: 5
***** ***** ***** ***** *****
Mirrored rhombus star pattern screenshot
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; //Reads number of rows and columns printf("Enter rows: "); scanf("%d", &M); printf("Enter columns: "); scanf("%d", &N); for(i=1; i<=M; i++) { //Prints trailing spaces for(j=1; j<i; j++) { printf(" "); } for(j=1; j<=N; j++) { printf("*"); } printf("\n"); } return 0; }
Mirrored parallelogram star pattern screenshot
Happy coding ;)