C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Loop Programs in C

Print multiplication table of a number

Introduction

A multiplication table helps display the product of a number with integers from 1 to 10 (or more).


For example, if the number is 5, then the table is:

5 × 1 = 5

5 × 2 = 10

...

5 × 10 = 50

We can easily print it using a loop in C.

 

C Program: Print multiplication table of a number

NOTE: The Program is written using for, while and do..while loop.
Method 1 is for loop, Method 2 is while loop and Method 3 is do..while loop

Method 1: Using for loop

C

#include <stdio.h>

 

int main() {

    int num, i;

 

    // Input

    printf("Enter a number to print its multiplication table: ");

    scanf("%d", &num);

 

    // Print table

    printf("Multiplication Table of %d:\n", num);

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

        printf("%d x %d = %d\n", num, i, num * i);

    }

 

    return 0;

}

Output

 
OUTPUT :
Enter a number to print its multiplication table: 5

Multiplication Table of 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Explanation

  1. The user enters the number.
  2. The loop runs from 1 to 10.
  3. In each iteration, the program calculates num * i.
  4. It prints the result in the format num x i = product.

 

C Program: Print multiplication table of a number

Method 2: Using while loop

The while loop is an alternative to the for loop.
It can be used to print the multiplication table by controlling a counter variable manually.

C

#include <stdio.h>

 

int main() {

    int num, i = 1;

 

    // Input

    printf("Enter a number to print its multiplication table: ");

    scanf("%d", &num);

 

    printf("Multiplication Table of %d:\n", num);

 

    // While loop

    while (i <= 10) {

        printf("%d x %d = %d\n", num, i, num * i);

        i++; // Increment counter

    }

 

    return 0;

}

Output

 
OUTPUT :
Enter a number to print its multiplication table: 7

Multiplication Table of 7:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

Explanation

  1. Initialize counter i = 1.
  2. Loop continues while i <= 10.
  3. Print num * i in each iteration.
  4. Increment i by 1 after each loop.

 

C Program: Print multiplication table of a number

Method 3: Using do..while loop

The do-while loop executes the loop body at least once before checking the condition.
This is useful for printing a multiplication table since we always want at least the first multiplication (num × 1) to appear.

C

#include <stdio.h>

 

int main() {

    int num, i = 1;

 

    // Input

    printf("Enter a number to print its multiplication table: ");

    scanf("%d", &num);

 

    printf("Multiplication Table of %d:\n", num);

 

    // Do-while loop

    do {

        printf("%d x %d = %d\n", num, i, num * i);

        i++; // Increment counter

    } while (i <= 10);

 

    return 0;

}

Output

 
OUTPUT :
Enter a number to print its multiplication table: 9

Multiplication Table of 9:
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
9 x 10 = 90

Explanation

  1. Initialize i = 1.
  2. The do block executes first and prints num × i.
  3. Increment i by 1 after printing.
  4. The loop continues while i <= 10.
  5. Stops after printing the 10th multiple.