OneCompiler

C Program to print Multiplication table of a given number

459

In this post, let's learn how to print multiplication table of a given number.

C program to generate multiplication table:

#include <stdio.h>
int main() {
    int num;
    printf("Enter an integer: \n");
    scanf("%d", &num); // take input form User
    for (int i = 1; i <= 10; i++) { // Iterate for loop for 10 times
        printf("%d * %d = %d \n", num, i, num * i);
    }
    return 0;
}

Result

Consider you have provided 16 as your input, then below is the output

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160

If you want to generate the multiplication table to other range like 20, provide i<=20 in the for loop condition which generates the output as below.

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160 
16 * 11 = 176 
16 * 12 = 192 
16 * 13 = 208 
16 * 14 = 224 
16 * 15 = 240 
16 * 16 = 256 
16 * 17 = 272 
16 * 18 = 288 
16 * 19 = 304 
16 * 20 = 320

You can generate multiplication table for any other integer here by providing the integer value in the stdin section.