C Program to Generate Multiplication Table

CodingTute

C Program to Generate Multiplication Table

In this example, you will learn to generate a multiplication table up to 10 for the given number.

Program to Generate Multiplication Table

#include <stdio.h>

int main()
{
    int num, i;
    printf("Enter Number: ");
    scanf("%d", &num);
    //loop to calculate and print table
    for(i=1; i<=10; i++){
        printf("%d x %d = %d\n", num, i, num*i);
    }

    return 0;
}

Output

Enter 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

Explanation

Firstly, we read input from the user and store it to num variable.

For the given number we need to calculate and print the table upto 10. So, we will run a loop starting from 1 to 10. We choose for loop in our case because we can use the index variable in our calculation.

Follow us on Facebook, YouTube, Instagram, and Twitter for more exciting content and the latest updates.

Exit mobile version