Table Forming by Multiplying Using While Loop


Explanation

The while loop can be used to generate the multiplication table of a number. In this program, the user enters a number, and the loop starts from 1 and continues up to 10. During each iteration, the entered number is multiplied by the current value of the loop variable and the result is displayed in table format.

How It Works?

  • Step 1: Accept a number from the user.
  • Step 2: Initialize the variable k with 1.
  • Step 3: The while loop checks whether k <= 10.
  • Step 4: Multiply the entered number by k and display the result.
  • Step 5: Increase the value of k by 1.
  • Step 6: Repeat the process until the condition becomes false.

Example Program


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

main()
{

    int k, no;

    clrscr();

    printf("\nEnter any number : ");
    scanf("%d", &no);

    k = 1;

    while(k <= 10)
    {

        printf("\n%d * %d = %d", no, k, no * k);

        k = k + 1;

    }

    getch();

}

Output

Enter any number : 5

5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Practice Exercises

Task 1: Write a C program using the while loop to display the multiplication table of a number entered by the user from 1 to 20.

Goal: Learn how to use the while loop to perform repeated multiplication and display a complete multiplication table.
💡 Hint: Accept a number from the user. Initialize k with 1. Use the while loop condition k <= 20. Multiply the entered number with k and increase the value of k by 1 after every iteration.
💡 Show Solution

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

main()
{

    int k, no;

    clrscr();

    printf("\nEnter any number : ");
    scanf("%d", &no);

    k = 1;

    while(k <= 20)
    {

        printf("\n%d * %d = %d", no, k, no * k);

        k = k + 1;

    }

    getch();

}

Output
Enter any number : 3

3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
...
3 * 20 = 60
Explanation: The program accepts a number from the user and initializes the variable k with 1. The while loop runs until k becomes greater than 20. In each iteration, the program multiplies the entered number with k and displays the result. After printing each table value, k is increased by 1.