***** **** *** ** * ** *** **** *****If you were looking for reverse of this pattern then find it here how to print left arrow star pattern.
Required knowledge:
Basic C programming, For loopLogic:
This pattern is a combination of two patterns hence, let's first divide it into two parts where the first upper part looks like:***** **** *** **and the second bottom part looks like:
* ** *** **** *****Now if you have noticed total number of spaces in upper part is 2*rownumber - 2 per row and bottom part contains total 2*n - 2*rownumber spaces per row (where n is the total number of rows). And if you ignore the trailing spaces, then the upper part star pattern would look similar to inverted right triangle star pattern and bottom part to simple right triangle star pattern which can be easily printed.
Program to print right arrow star pattern
/** * C program to print right arrow star pattern */ #include <stdio.h> int main() { int i, j, n; //Reads number of rows from user printf("Enter value of n : "); scanf("%d", &n); //Prints the upper part of the arrow for(i=1; i<n; i++) { //Prints trailing (2*rownumber-2) spaces for(j=1; j<=(2*i-2); j++) { printf(" "); } //Prints inverted right triangle star pattern for(j=i; j<=n; j++) { printf("*"); } printf("\n"); } //Prints lower part of the arrow for(i=1; i<=n; i++) { //Prints trailing (2*n - 2*rownumber) spaces for(j=1; j<=(2*n - 2*i); j++) { printf(" "); } //Prints simple right triangle star pattern 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 or 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.