Thursday 21 August 2014

Filled Under: ,

C program to Generate Multiplication Table

Share


This program asks user to enter an integer and this program will generate the multiplication table upto 10.

Example of C program to Generate Multiplication Table

/* C program to find multiplication table up to 10. */
#include <stdio.h>
int main()
{
    int n, i;
    printf("Enter an integer to find multiplication table: ");
    scanf("%d",&n);
    for(i=1;i<=10;++i)
    {
        printf("%d * %d = %dn", n, i, n*i);
    }
    return 0;
}
Output

Enter an integer to find multiplication table: 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

Explanation

This program generates multiplication table of an integer up 10. But, this program can be made more user friendly by giving option to user to enter number up to which, he/she want to generate multiplication table. The source code below will perform this task.

#include <stdio.h>
int main()
{
    int n, range, i;
    printf("Enter an integer to find multiplication table: ");
    scanf("%d",&n);
    printf("Enter range of multiplication table: ");
    scanf("%d",&range);
    for(i=1;i<=range;++i)
    {
        printf("%d * %d = %dn", n, i, n*i);
    }
    return 0;
}
Output

Enter an integer to find multiplication table: 6
Enter range of multiplication table: 4
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24