C Program to Print Multiplication Table of Given Number

1. Introduction

Multiplication tables form the foundation of arithmetic operations and are frequently taught at early stages in schools. They're useful tools for quick calculations and improving mathematical proficiency. In this guide, we'll demonstrate a C program that prints the multiplication table for a given number.

2. Program Overview

1. Prompt the user to enter the number for which the multiplication table is to be generated.

2. Use a loop to iterate through numbers from 1 to 10 (or any desired range).

3. During each iteration, calculate and print the result of the multiplication of the given number with the current iterator.

3. Code Program

#include <stdio.h>

int main() {
    int num, i;

    // Asking user to input the number
    printf("Enter the number: ");
    scanf("%d", &num);

    // Printing multiplication table
    for(i = 1; i <= 10; i++) {
        printf("%d x %d = %d\n", num, i, num * i);
    }

    return 0;
}

Output:

Enter the number: 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

4. Step By Step Explanation

1. The program starts by defining the necessary variables: num (to store the user's number) and i (to use as an iterator in the loop).

2. We then prompt the user to input a number.

3. Using a for loop, we iterate from 1 to 10. During each iteration, the multiplication of the entered number with the iterator i is calculated and printed.

4. Thus, the loop runs 10 times, printing each line of the multiplication table for the entered number.

Comments