Code :
#include <stdio.h>int main(){ int i, j, k, l; for (i = 1; i <= 4; i++) { for (j = 5; j >= i; j--) { printf("*"); } for (k = 2; k <= (i*2)-1; k++) { printf(" "); } for (l = 5; l >= i; l--) { printf("*"); } printf("\n"); }
for (i = 5; i >= 1; i--) { for (j = 5; j >= i; j--) { printf("*"); } for (k = 2; k <= (i*2)-1; k++) { printf(" "); } for (l = 5; l >= i; l--) { 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. -
First Outer Loop (Top Section): The first outer
for
loop (i = 1 to i <= 4
) controls the rows of the top section, with stars decreasing and spaces increasing as the row number increases. -
Inner Loop 1 (Stars on the Left for Top Section): The first inner
for
loop (j = 5 to j >= i
) prints stars (*
) on the left side, decreasing the number of stars as the row number increases. -
Inner Loop 2 (Spaces for Top Section): The second inner
for
loop (k = 2 to k <= (i * 2) - 1
) prints spaces to separate the two sets of stars, with the number of spaces increasing as the row number increases. -
Inner Loop 3 (Stars on the Right for Top Section): The third inner
for
loop (l = 5 to l >= i
) prints stars (*
) on the right side, creating symmetry with the left side. -
Second Outer Loop (Bottom Section): The second outer
for
loop (i = 5 to i >= 1
) controls the rows of the bottom section, with stars increasing and spaces decreasing as the row number decreases. -
Inner Loop 1 (Stars on the Left for Bottom Section): The first inner
for
loop (j = 5 to j >= i
) prints stars (*
) on the left side, increasing the number of stars as the row number decreases. -
Inner Loop 2 (Spaces for Bottom Section): The second inner
for
loop (k = 2 to k <= (i * 2) - 1
) prints spaces to separate the two sets of stars, with the number of spaces decreasing as the row number decreases. -
Inner Loop 3 (Stars on the Right for Bottom Section): The third inner
for
loop (l = 5 to l >= i
) prints stars (*
) on the right side, creating symmetry with the left side. -
New Line:
printf("\n");
moves the output to a new line after printing each row.
Output :
********** **** **** *** *** ** ** * * ** ** *** *** **** **** **********