Multiplication Table Formation Number Given By User Using For Loop


Explanation

The for loop is used to generate the multiplication table of a number entered by the user. The program accepts a number from the user and repeats the multiplication process from 1 to 10. Each iteration calculates and displays the multiplication result.

How It Works?

  • Step 1: Declare integer variables k and no.
  • Step 2: Accept a number from the user.
  • Step 3: Initialize k = 1 in the for loop.
  • Step 4: The loop runs until k <= 10.
  • Step 5: Multiply the given number with the value of k.
  • Step 6: Display the multiplication table.
  • Step 7: Increase the value of k by 1 and repeat the process.



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


main()

{


    int
    k, no;


    clrscr();


    printf(
    "\n Enter any no"
    );


    scanf(
    "%d",
    &no);


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

    {


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


    }


    getch
    ();


}


Output

Enter any no 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 for loop to accept a number from the user and display its multiplication table from 1 to 20.

Goal: Learn how to use the for loop for repeated calculations and generate multiplication tables.

💡 Hint: Declare variables no and k. Accept a number from the user. Use a for loop with condition k <= 20 and display the multiplication result using no * k.
💡 Show Solution


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


main()

{


    int
    k, no;


    clrscr();


    printf
    (
    "\n Enter any no"
    );


    scanf
    (
    "%d",
    &no);


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

    {


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


    }


    getch
    ();


}


Output
Enter any no 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 * 11 = 33

3 * 12 = 36

3 * 13 = 39

3 * 14 = 42

3 * 15 = 45

3 * 16 = 48

3 * 17 = 51

3 * 18 = 54

3 * 19 = 57

3 * 20 = 60
Explanation: The program accepts a number from the user and uses a for loop to generate its multiplication table. The loop starts from 1 and continues until 20. In each iteration, the number is multiplied by the loop counter and the result is displayed.