C Program to Display Multiplication Table of a Given Number

Multiplication table

C programs to display the multiplication table of a number have been shown here. Both the iterative and recursive approaches have been covered below.






1. C Program & output to display multiplication table of a number using iteration

Code has been copied
/**************************************
	alphabetacoder.com
C Program to display multiplication
table of a given number using iteration
***************************************/

#include<stdio.h>

int main() {
    // delclare variables
    int i, n, r;

    // take input of a number
    printf("Enter a number: ");
    scanf("%d", & n);
    printf("Enter the range: ");
    scanf("%d", & r);

    printf("\nMultiplication table of %d:\n", n);
    // display table
    for (i = 1; i <= r; i++) {
        printf("%d x %d = %d\n", n, i, n * i);
    }

    return 0;
}

Output


Enter a number: 11

Enter the range: 20

Multiplication table of 11:

11 x 1 = 11

11 x 2 = 22

11 x 3 = 33

11 x 4 = 44

11 x 5 = 55

11 x 6 = 66

11 x 7 = 77

11 x 8 = 88

11 x 9 = 99

11 x 10 = 110

11 x 11 = 121

11 x 12 = 132

11 x 13 = 143

11 x 14 = 154

11 x 15 = 165

11 x 16 = 176

11 x 17 = 187

11 x 18 = 198

11 x 19 = 209

11 x 20 = 220





2. C Program & output to display multiplication table of a number using recursion

Code has been copied
/***************************************
	alphabetacoder.com
C Program to display multiplication
table of a given number using recursion
****************************************/

#include<stdio.h>

// recursive function to display 
// multiplication table
void multiplication_table(int n, int r) {
    // exit condition of recursive call
    if (r == 0)
        return;
    // call function
    multiplication_table(n, r - 1);
    // display the line
    printf("%d x %d = %d\n", n, r, n * r);
}

int main() {
    // delclare variables
    int i, n, r;

    // take input of a number
    printf("Enter a number: ");
    scanf("%d", & n);
    printf("Enter the range: ");
    scanf("%d", & r);

    printf("\nMultiplication table of %d:\n", n);
    // call function to display multiplication table
    multiplication_table(n, r);

    return 0;
}

Output


Enter a number: 10

Enter the range: 10

Multiplication table of 10:

10 x 1 = 10

10 x 2 = 20

10 x 3 = 30

10 x 4 = 40

10 x 5 = 50

10 x 6 = 60

10 x 7 = 70

10 x 8 = 80

10 x 9 = 90

10 x 10 = 100