***** **** *** ** * ** *** **** *****If you were looking for right arrow star pattern find it here - how to print right arrow star pattern.
Required knowledge:
Basic C programming, For loopLogic to print left arrow star pattern
Let's first divide this pattern in two parts to make our task easy. Where the first upper part looks like:***** **** *** **and the bottom part looks like:
* ** *** **** *****Now, if you have noticed number of spaces in the upper part per row is n - rownumber and bottom part contains rownumber - 1 spaces per row (where n is the total number of rows). And if you ignore the trailing spaces in both parts you will notice that the upper part is similar to inverted right triangle and lower part is similar to right triangle star pattern.
Program to print left arrow star pattern
/** * C program to print left arrow star pattern */ #include <stdio.h> int main() { int i, j, n; //Reads the 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 (n-rownumber) spaces for(j=1; j<=(n-i); j++) { printf(" "); } //Prints inverted right triangle for(j=i; j<=n; j++) { printf("*"); } printf("\n"); } //Prints bottom part of the arrow for(i=1; i<=n; i++) { //Prints trailing (rownumber-1) spaces for(j=1; j<i; j++) { printf(" "); } //Prints the right triangle 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.