C Program To Print Equilateral Triangle | Pyramid Star Pattern
In this tutorial, we are going to see how to write a C program to print an Equilateral triangle or pyramid star pattern in C. To display a pyramid or an isosceles triangle of N lines we are going to use the for loop. Below is the logic for displaying a pyramid or an isosceles triangle of N lines made of stars in C programming.
Input:
Number of Lines: 5
Output:
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
C Program To Print Equilateral Triangle | Pyramid Star Pattern
#include <stdio.h>
int main()
{
int i, j=0, s, lines;
printf("Enter the number of lines: ");
scanf("%d",&lines);
for(i=1; i<=lines; ++i, j=0)
{
for(s=1; s<=lines-i; ++s)
{
printf(" ");
}
while(j != 2*i-1)
{
printf("* ");
++j;
}
printf("\n");
}
return 0;
}
Output:
Enter the number of lines: 5
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *




