Print Numbers 10 To 1 Using For Loop


Explanation

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?

  • Step 1: Declare the variable k.
  • Step 2: Initialize k with 10 in the for loop.
  • Step 3: The loop checks whether k >= 1.
  • Step 4: Display the current value of k.
  • Step 5: Decrease the value of k by 1 using k = k - 1.
  • Step 6: Repeat the process until the condition becomes false.

Example Program


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

main()
{

    int k;

    clrscr();

    for(k = 10; k >= 1; k = k - 1)
    {

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

    }

    getch();

}

Output

10
9
8
7
6
5
4
3
2
1

Practice Exercises

Task 1: Write a C program using the for loop to print the numbers from 20 to 1.

Goal: Learn how to use the for loop to display numbers in descending order by decreasing the loop variable after each iteration.

💡 Hint: Initialize k with 20. Use the loop condition k >= 1 and decrease the value of k by 1 after every iteration using k = k - 1.
💡 Show Solution

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

main()
{

    int k;

    clrscr();

    for(k = 20; k >= 1; k = k - 1)
    {

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

    }

    getch();

}

Output
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
Explanation: The program uses a 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.