* ** *** **** ***** **** *** ** *If you are looking for reverse of this pattern find it here how to print half diamond star pattern.
Required knowledge:
Basic C programming, For loopLogic:
Here to print this pattern I am going to bisect this pattern to make the task easy. The first upper half look likes:* ** *** **** *****And the lower half look likes:
**** *** ** *Now, if you have done with previous patterns you will find that the first half is the mirrored right triangle star pattern and the second half is the inverted mirrored right triangle star pattern. Hence, in-order to get the final pattern we need to write the codes of both the pattern one by one.
Program:
/** * C program to print mirrored half diamond star pattern */ #include <stdio.h> int main() { int i, j, n; //Reads number of columns to be printed from user printf("Enter value of n : "); scanf("%d", &n); //Prints the upper half part of the pattern for(i=1; i<=n; i++) { for(j=i; j<n; j++) { printf(" "); } for(j=1; j<=i; j++) { printf("*"); } printf("\n"); } //Prints the lower half part of the pattern for(i=n; i>=1; i--) { for(j=i; j<=n; j++) { printf(" "); } for(j=1; j<i; j++) { printf("*"); } printf("\n"); } return 0; }
Output
Enter value of n : 5
*
**
***
****
*****
****
***
**
*
*
**
***
****
*****
****
***
**
*
Screenshot:
Happy coding ;)
You may also like
- All star patterns programs index.
- For loop programming exercises and solutions.
- If else programming exercises and solutions.
- C program to check whether a triangle is Equilateral, Scalene or Isosceles.
- C program to check whether a triangle is valid or not.
- C program to find GCD(HCF) of two numbers.
- C program to find LCM of two numbers.
- C program to find all factors of a given number.
- C program to check whether a number is Perfect number or not.
- C program to check whether a number is Strong number or not.
- C program to print Pascal triangle of n rows.
- C program to print fibonacci series.
- C program to check whether a number is Prime number or not.