Code :
#include <stdio.h>int main(){ int i, j; for (i = 5; i >= 1; i--) { for (j = 5; j >= i; j--) { printf("%d", j); } 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 = 5
toi >= 1
) controls the number of rows. The value ofi
decreases from 5 to 1, determining how many digits will be printed in each row. -
Inner Loop (Columns): The inner
for
loop (j = 5
toj >= i
) prints numbers starting from 5 down to the current value ofi
. In each iteration of the outer loop, the inner loop prints decreasing values from 5 untili
. -
New Line:
printf("\n");
moves the output to a new line after printing each row
Output :
5
54
543
5432
54321