English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structures

C Language Files

C Others

C Language Reference Manual

C program generates multiplication table

Comprehensive Collection of C Programming Examples

In this example, you will learn how to generate a multiplication table for the number entered by the user.

To understand this example, you should understand the followingC programmingTopic:

The following program takes an integer input from the user and generates a multiplication table up to10multiplication table.

Multiplication table up to10

#include <stdio.h>
int main() {
    int n, i;
    printf("Input an integer: ");
    scanf("%d", &n);
    for (i = 1; i <= 10; ++i) {
        printf("%d * %d = %d \n", n, i, n * i);
    }
    return 0;
}

Output Result

Enter an Integer: 9
9 * 1 = 9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
9 * 10 = 90

The following program has been slightly modified to generate a multiplication table for a range (where range is also a positive integer entered by the user).

Multiplication table maximum range

#include <stdio.h>
int main() {
    int n, i, range;
    printf("Input an integer: ");
    scanf("%d", &n);
    printf("Input range: ");
    scanf("%d", &range);
    for (i = 1; i <= range; ++i) {
        printf("%d * %d = %d \n", n, i, n * i);
    }
    return 0;
}

Output Result

Enter an Integer: 12
Input Range: 8
12 * 1 = 12 
12 * 2 = 24 
12 * 3 = 36 
12 * 4 = 48 
12 * 5 = 60 
12 * 6 = 72 
12 * 7 = 84 
12 * 8 = 96

Comprehensive Collection of C Programming Examples