Multiplication Table Program in C

Multiplication tables are useful for practicing nested loops. The outer loop selects a row and the inner loop generates the values across that row.

10 × 10 Multiplication Grid with while Loops Top ↑

#include <stdio.h>

int main(void) {
    int row = 1;

    while (row <= 10) {
        int column = 1;

        while (column <= 10) {
            printf("%4d", row * column);
            column++;
        }

        putchar('\n');
        row++;
    }

    return 0;
}

Table for a User-Entered Number Top ↑

#include <stdio.h>

int main(void) {
    int number;

    printf("Enter a number: ");
    if (scanf("%d", &number) != 1) {
        printf("Invalid input.\n");
        return 1;
    }

    for (int i = 1; i <= 10; i++) {
        printf("%d x %d = %d\n",
               number, i, number * i);
    }

    return 0;
}

Inverted Multiplication Grid Top ↑

#include <stdio.h>

int main(void) {
    for (int row = 10; row >= 1; row--) {
        for (int column = 10; column >= 1; column--) {
            printf("%4d", row * column);
        }

        putchar('\n');
    }

    return 0;
}

Multiplication Grid with Row Sums Top ↑

#include <stdio.h>

int main(void) {
    for (int row = 1; row <= 10; row++) {
        int row_sum = 0;

        for (int column = 1; column <= 10; column++) {
            int product = row * column;
            printf("%4d", product);
            row_sum += product;
        }

        printf(" | Sum = %d\n", row_sum);
    }

    return 0;
}

Related: while loops, for loops, and loop patterns.





plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer