***** * * * * ** *
Required knowledge:
Basic C programming, If else, For loopBefore continuing to this pattern you must go through how to print hollow inverted right triangle star pattern.
Logic:
If you look to the pattern carefully you will find that it is way similar to hollow inverted right triangle if we add trailing spaces. So what we need is we need to make a little change in the hollow inverted right triangle star pattern program, we need to add an extra inner loop that will print spaces before the star gets printed. And if you look to the spaces you will notice they are in a special pattern (i.e. spaces per row is spaces = row_number - 1).Program:
/** * C program to print hollow mirrored inverted right triangle star pattern */ #include <stdio.h> int main() { int i, j, n; //Reads number of rows to be printed from user printf("Enter value of n : "); scanf("%d", &n); for(i=1; i<=n; i++) { //Prints trailing spaces before star gets printed for(j=1; j<i; j++) { printf(" "); } //Prints hollow inverted right triangle for(j=i; j<=n; j++) { if(j==i || j==n || i==1) { 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 check whether a triangle is Equilateral, Scalene or Isosceles.
- C program to check whether a triangle is valid or not.
- C program to find profit or loss.
- C program to print table 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.