Display Pyramid triangle stars in C Programing Language with source code
This is one of the basic and common program mostly asked in interview question and the pyramid triangle program is the best example for loop example. Our aim of the program is to display starts like below
*
***
*****
*******
*********
Just use the below source code program to display pyramid triangle.
//pyramid-triangle.c
#include<stdio.h>
#include<conio.h>
main()
{
int i, j, n, temp;
printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);
temp = n;
for ( i = 1 ; i <= n ; i++ ){
for ( j = 1 ; j < temp ; j++ )
printf(" ");
temp--;
for ( j = 1 ; j <= 2*i - 1 ; j++ )
printf("*");
printf("
");
}
getch();
return 0;
}