Print Numbers 1 To 10 Using For Loop


Explanation

The for loop is used when the number of iterations is known in advance. In this program, the loop starts from 1 and continues up to 10. During each iteration, the current value of the variable k is displayed on the screen.

Definition:

This program uses a for loop to print the numbers from 1 to 10. The loop executes 10 times and displays one number during each iteration.

How It Works?

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

Syntax:

for(k = 1; k <= 10; k++)
{
    printf("%d", k);
}

Example Program


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

main()
{

    int k;

    clrscr();

    for(k = 1; k <= 10; k++)
    {

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

    }

    getch();

}

Output

1
2
3
4
5
6
7
8
9
10

Practice Exercises

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

Goal: Learn how to use the for loop to display a sequence of numbers by changing the loop condition.

💡 Hint: Initialize k with 1. Use the loop condition k <= 20 and increase the value of k by 1 after each iteration.
💡 Show Solution

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

main()
{

    int k;

    clrscr();

    for(k = 1; k <= 20; k++)
    {

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

    }

    getch();

}

Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Explanation: The program uses a for loop to print the numbers from 1 to 20. The loop starts with k = 1, continues while k <= 20, and increments k by 1 after each iteration.