Program to print vertical pyramid in C

C program to accept the number of rows of pyramid from user and print the correspondence star triangle.

*
* *
* * *
* * * *
* * *
* *
*

Solution:


/*c program for star pyramid*/
#include<stdio.h>
int main()
{
int num,r,c;
printf("Enter number of rows : ");
scanf("%d", &num);
for(r=1; r<=(num/2)+1; r++)
{
for(c=1; c<=r; c++)
printf("*");
printf("\n");
}
for(r=1; r<=(num/2); r++)
{
for(c=r; c<=num/2; c++)
printf("*");
printf("\n");
}
return 0;
}


Output: 

birwa.org


Post a Comment