In this article, I will show you, How to write a C program to print mirrored rhombus star pattern. Here, one thing is important to know that all sides of the rhombus must be the same.
Logic to write C program to print mirrored rhombus star pattern:
It is very easy to print a mirrored rhombus star pattern in C, below I have mentioned a few steps to print a mirrored rhombus pattern in C:
- You must know the side of the rhombus.
- There should be three-loop, two inner and one outer.
- Inner loops print the spaces and stars.
- After completing each iteration of the inner loops, the outer loop prints the new line.
See the, C program to print the mirrored rhombus pattern:
#include <stdio.h> int main() { int x = 0,y = 0; unsigned int rows = 0; printf("Enter the number of rows = "); scanf("%u",&rows); for(x=1; x<=rows; ++x) { // Print spaces for(y=1; y<= x; ++y) { printf(" "); } // Print stars for(y=1; y<=rows; ++y) { //Print star printf("*"); } // Print new line printf("\n"); } return 0; }
Output:
Code Analysis:
It asks the user to enter the side of the rhombus.
printf("Enter the number of rows = "); scanf("%u",&rows);
The code contains the three for loop, two inner loop, and one outer loop. The first inner loop prints space x times. The second inner loop print star row times using the printf function. The outer loop print the newline after each iteration of the inner loops.
for(x=1; x<=rows; ++x) { // Print spaces for(y=1; y<= x; ++y) { printf(" "); } // Print stars for(y=1; y<=rows; ++y) { //Print star printf("*"); } // Print new line printf("\n"); }