The while loop can also be used to print numbers in reverse order. In this program, the variable k is initialized with the value 10. During each iteration, the current value of k is displayed and then decreased by 1. The loop continues until the value of k becomes less than 1.
How It Works?
k with the value 10.while loop checks whether k >= 1.k is displayed.k by 1.#include <stdio.h> #include <conio.h> main() { int k = 10; clrscr(); while(k >= 1) { printf("\n%d", k); k = k - 1; } getch(); }
while loop to print numbers from 10 to 1 in reverse order.while loop to print numbers in descending order by decreasing the value of the loop control variable.10. Use the condition k >= 1 and decrease the value of k by 1 after each iteration.#include <stdio.h> #include <conio.h> main() { int k = 10; clrscr(); while(k >= 1) { printf("\n%d", k); k = k - 1; } getch(); }
k with the value 10. The while loop continues as long as k >= 1. During each iteration, the current value of k is displayed, and then k is decreased by 1. This prints the numbers in reverse order from 10 to 1.