The for loop can also be used to print numbers in reverse order. In this program, the loop starts from 10 and continues until 1. During each iteration, the value of the variable k is displayed, and its value is decreased by 1.
How It Works?
k.k with 10 in the for loop.k >= 1.k.k by 1 using k = k - 1.#include <stdio.h> #include <conio.h> main() { int k; clrscr(); for(k = 10; k >= 1; k = k - 1) { printf("\n %d", k); } getch(); }
for loop to print the numbers from 20 to 1.for loop to display numbers in descending order by decreasing the loop variable after each iteration.k with 20. Use the loop condition k >= 1 and decrease the value of k by 1 after every iteration using k = k - 1.#include <stdio.h> #include <conio.h> main() { int k; clrscr(); for(k = 20; k >= 1; k = k - 1) { printf("\n %d", k); } getch(); }
for loop to print the numbers from 20 to 1. The loop starts with k = 20, continues while k >= 1, and decreases k by 1 after each iteration until all numbers are displayed.