* *** ***** ******* *********
Required knowledge:
Basic C programming, For loopLogic:
There can be many ways of thinking of the problem here I am discussing the easiest one. Here we need to print two things one is the trialing spaces and other is the equilateral triangle. As like other star pattern problems here also spaces are arranged in a special way i.e. each row contains n - row_number spaces (where n is the total number of rows).When you look to the total number of stars(*) in the equilateral triangle pattern you will notice that each row contains 2*rownumber - 1 stars.
Program:
/** * C program to print equilateral triangle or pyramid star pattern */ #include <stdio.h> int main() { int i, j, n; //Reads number of rows to be printed printf("Enter value of n : "); scanf("%d", &n); for(i=1; i<=n; i++) { //Prints trailing spaces for(j=i; j<n; j++) { printf(" "); } //Prints the pyramid pattern for(j=1; j<=(2*i-1); 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 an alphabet is uppercase or lowercase.
- C program to input month number and print its month name.
- 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.