description: This program is simple print half pyramid using loops
</code>:print half pyramid of star(*)
/* C Program to print half pyramid using given input number */
#include <stdio.h>
int main()
{
int p, k, number;
printf("Enter number of rows :");
scanf("%d",&number);
for(p=0; p<=number;p++)
{
for(k=0; k<p; k++)
{
printf(" *");
}
printf("\n");
}
return 0;
}
output:
Enter number of rows :6
*
* *
* * *
* * * *
* * * * *
* * * * * *
Explanation:As you seen simple logic is use in this program first derclare
variables and get input from user how many rows you want to print.
start first outer loop p=0 and p<=number and p++ and start innner k loop k start
from zero and repeat util k<p and print (" *") and close inner loop after close loop
print new line each time whenever inner loop is close and close outer p loop.
return 0 and close main() function