Printing Number 10 to 1


Explanation

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?

  • Step 1: Initialize the variable k with the value 10.
  • Step 2: The while loop checks whether k >= 1.
  • Step 3: If the condition is true, the current value of k is displayed.
  • Step 4: Decrease the value of k by 1.
  • Step 5: Repeat the process until the condition becomes false.

Example Program


#include <stdio.h>
#include <conio.h>

main()
{

    int k = 10;

    clrscr();

    while(k >= 1)
    {

        printf("\n%d", k);

        k = k - 1;

    }

    getch();

}

Output

10
9
8
7
6
5
4
3
2
1

Practice Exercises

Task 1: Write a C program using the while loop to print numbers from 10 to 1 in reverse order.

Goal: Learn how to use the while loop to print numbers in descending order by decreasing the value of the loop control variable.
💡 Hint: Initialize the variable with 10. Use the condition k >= 1 and decrease the value of k by 1 after each iteration.
💡 Show Solution

#include <stdio.h>
#include <conio.h>

main()
{

    int k = 10;

    clrscr();

    while(k >= 1)
    {

        printf("\n%d", k);

        k = k - 1;

    }

    getch();

}

Output
10
9
8
7
6
5
4
3
2
1
Explanation: The program initializes the variable 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.