47. WRITE A C PROGRAM TO PRINT EQUILATERAL TRIANGLE (PYRAMID) STAR PATTERN

    * 
   ***
  *****
 *******
*********
/* 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    
    *
   ***
  *****
 *******
*********

Comments