Code :
#include <stdio.h>int main(){ int i, j, k; for (i = 1; i <= 5; i++) { for (j = 5; j >= i; j--) { printf(" "); } for (k = 1; k <= (i*2)-1; k++) { printf("*"); } printf("\n"); } return 0;}
-
Header File:
#include <stdio.h>
is needed to useprintf()
for printing output. -
Main Function: The program starts from
int main()
. It returns 0 to indicate successful completion. -
Outer Loop (Rows): The outer
for
loop (i = 1 to i <= 5
) controls the number of rows, with each row having an increasing number of stars. -
Inner Loop 1 (Spaces): The first inner
for
loop (j = 5 to j >= i
) prints spaces to center-align the stars, decreasing the number of spaces as the row number increases. -
Inner Loop 2 (Stars): The second inner
for
loop (k = 1 to k <= (i * 2) - 1
) prints stars (*
), with the number of stars increasing according to the row number. -
New Line:
printf("\n");
moves the output to a new line after printing each row.
Output :
* *** ***** ******* *********