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

C Language Basic Tutorial

C Language Flow Control

Funções do C

Matrizes do C

Ponteiros do C

Strings do C

C Language Structure

C Language File

C Others

C Language Reference Manual

C program generates multiplication table

大全 de Programação em C

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 be familiar with 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, i, n * i);
    }
    return 0;
}

Resultado de Saída

Insira um inteiro: 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, i, n * i);
    }
    return 0;
}

Resultado de Saída

Insira um inteiro: 12
Intervalo de Entrada: 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

大全 de Programação em C