* ** * * * * *****
Required knowledge:
Basic C programming, If else, For loopBefore printing hollow mirrored right triangle, you must know how to print hollow right triangle and mirrored right triangle star pattern.
Logic:
As when you look to the pattern carefully you will find that this pattern is similar to hollow right triangle if we add trailing spaces before printing *. And if you look to the spaces you will find that spaces are arranged in a special pattern of decreasing order of row (i.e. first row contains n-1=4 spaces and second row contains 3 and so on... where n is the number of rows to be printed). So talking about the program if we add an extra inner loop (that print spaces) to the hollow right triangle program then this pattern can be simply made.Program:
/** * C program to print hollow mirrored right triangle star pattern */ #include <stdio.h> int main() { int i, j, n; //Reads number of rows to be printed from user printf("Enter number of rows : "); scanf("%d", &n); for(i=1; i<=n; i++) { //Prints trailing spaces for(j=i; j<n; j++) { printf(" "); } //Prints hollow right triangle for(j=1; j<=i; j++) { if(i==n || j==1 || j==i) { printf("*"); } else { 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 print all alphabets from a to z.
- C program to print table of any number.
- C program to calculate sum of digits.
- C program to find reverse of any number.
- C program to check whether a number is palindrome or not.
- C program to print Pascal triangle of n rows.
- C program to find factorial of any number.
- C program to print fibonacci series.
- C program to check whether a number is Prime number or not.
- C program to print all prime numbers between 1 to n.
- C program to print sum of all prime numbers between 1 to n.