* ** *** **** *****
Required knowledge:
Basic C programming, For loopBefore printing mirrored right triangle star pattern you must know how to print simple right triangle star pattern.
Logic:
If you have gone though the previous post to print the right triangle star pattern then printing this wouldn't be difficult. What you need is to add an extra inner loop that will print spaces before * gets printed. And if you carefully look to the spaces you will find a special pattern of spaces that are eventually in decreasing order of row (i.e. first row contains n-1=4 spaces, followed by 3 and so on... Where n is the total number of rows).Program:
/** * C program to print mirrored right triangle star pattern series */ #include <stdio.h> int main() { int i, j, n; //Read number of rows to be printed from user printf("Enter value of n: "); scanf("%d", &n); for(i=1; i<=n; i++) { //Used for printing spaces in decreasing order of row for(j=i; j<n; j++) { printf(" "); } //Prints star in increasing order or row 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 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.