***** **** *** ** *
Required knowledge:
Basic C programming, For loopBefore going through this pattern you must go through my previous post how to print inverted right triangle star pattern as both are similar in nature.
Logic:
If you look to above pattern and inverted right triangle star pattern you will find that both are similar with one exception. This pattern contains extra trailing spaces. Spaces are also arranged in a specific pattern i.e. each row contains total row_number - 1 spaces.Program:
/** * C program to print reverse 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 value of n: "); scanf("%d", &n); for(i=1; i<=n; i++) { //Prints trailing spaces for(j=1; j<i; j++) { printf(" "); } //Prints right triangle for(j=i; j<=n; 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 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.