Mathematical Table Using Nested For Loop


Explanation

A for loop can be nested inside another for loop to display the multiplication tables of multiple numbers. In this program, the outer for loop controls the table number from 5 to 10, while the inner for loop multiplies each number by the values 1 to 10. The result is displayed in a tabular format.

How It Works?

  • Step 1: Declare the variables k and m.
  • Step 2: Display the heading "Table Of 5 to 10".
  • Step 3: Use the outer for loop to generate table numbers from 5 to 10.
  • Step 4: Use the inner for loop to multiply the current table number by values from 1 to 10.
  • Step 5: Display each multiplication result using the printf() function.
  • Step 6: After completing one table, print a new line to display the next table.
  • Step 7: Repeat the process until all tables from 5 to 10 are displayed.

Example Program


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

main()
{

    int k, m;

    clrscr();

    printf("Table Of 5 to 10");

    printf("\n\n");

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

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

            printf("%d\t", k * m);

        }

        printf("\n");

    }

    getch();

}

Output

Table Of 5 to 10
5   10  15  20  25  30  35  40  45  50
6   12  18  24  30  36  42  48  54  60
7   14  21  28  35  42  49  56  63  70
8   16  24  32  40  48  56  64  72  80
9   18  27  36  45  54  63  72  81  90
10  20  30  40  50  60  70  80  90  100

Practice Exercises

Task 1: Write a C program using nested for loops to display the multiplication tables from 2 to 6. Each table should contain the multiplication results from 1 to 10.

Goal: Learn how to use nested for loops to generate multiple multiplication tables using rows and columns.

💡 Hint: Use the outer for loop to control the table number from 2 to 6. Use the inner for loop to multiply each table number by values from 1 to 10.
💡 Show Solution

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

main()
{

    int k, m;

    clrscr();

    printf("Table Of 2 to 6");

    printf("\n\n");

    for(k = 2; k <= 6; k++)
    {

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

            printf("%d\t", k * m);

        }

        printf("\n");

    }

    getch();

}

Output
Table Of 2 to 6

2   4   6   8   10  12  14  16  18  20
3   6   9   12  15  18  21  24  27  30
4   8   12  16  20  24  28  32  36  40
5   10  15  20  25  30  35  40  45  50
6   12  18  24  30  36  42  48  54  60
Explanation: The program uses two for loops. The outer loop generates the table numbers from 2 to 6, while the inner loop multiplies each table number by the numbers from 1 to 10. After completing one table, the program moves to the next line and prints the next multiplication table.