In this tutorial you will learn about the C Program to Print Mirrored Half Diamond Star Pattern and its application with practical example.
C Program to Print Mirrored Half Diamond Pattern.
In this tutorial, we will learn to create a C program that will print a Mirrored Half Diamond Star Pattern using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C Programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
Step 1: Start the program. Step 2: Declaring the required variables. Step 3: Taking the input number of rows. Step 4: Generating the pattern using the loops. Step 5: Printing the pattern using the print function. Step 6: End the program. |
Program description to print a Mirrored Half diamond:-
In this program, we will first take the input number of rows from the user using a print function. Then we will use the number of rows in the loop to draw the pattern on the console using nest for loops. At last, we will print the pattern using a print function.
In this program, we will learn to create a Mirrored Half diamond-like pattern with the help of c programming.
Program Code:-
To create a Mirrored Half diamond pattern.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include<stdio.h>//including the header file int main()//Body of the main function { //Declaring the required variables for the program. int i, j, rw; //Taking the input from the user for the program. printf("Enter Number of rows for the Mirrored Half Diamond rows = "); //Scanning the input scanf("%d", &rw); printf("Mirrored Half Diamond Star Pattern\n"); //Creating the pattern to the console using the loops for(i = 1; i <= rw; i++) { for(j = 1; j <= rw - i; j++) { printf(" "); } for(j = 1; j <= i; j++) { //Printing the mirrored diamond row by row printf("*"); } printf("\n"); } for(i = rw - 1; i > 0; i--) { for(j = 1; j <= rw - i; j++) { printf(" "); } for(j = 1; j <= i; j++) { printf("*"); } printf("\n"); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- i = it will hold the integer value to control the parent for loop.
- j = it will hold the integer value to control the child for loop.
- rw = it will store the value for the input rows.
Taking the input and initializing the first parent for loop size and the number of rows.
Using for loop to print the creation of a pattern.
Program Code for Printing the pattern using the print function.