C Program To Print Multiplication Table Using While Loop


Lets write a C program to ask the user to input an integer value and then output multiplication table(up to 10) on to the console window.

Related Read:
Basic Arithmetic Operations In C
while loop in C programming

Simple Mathematical Trick — logical thinking

Source Code: C Program To Print Multiplication Table Using While Loop

 
#include < stdio.h >

int main()
{
    int num, count = 1;

    printf("Enter a number\n");
    scanf("%d", &num);

    printf("\nMultiplication table for %d is:\n\n", num);
    while(count <= 10)
    {
        printf("%d x %d = %d\n", num, count, (num*count));
        count++;
    }

    return 0;
}

Output 1:
Enter a number
2

Multiplication table for 2 is:

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

Output 2:
Enter a number
9

Multiplication table for 9 is:

9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
9 x 10 = 90

Output 3:
Enter a number
14

Multiplication table for 14 is:

14 x 1 = 14
14 x 2 = 28
14 x 3 = 42
14 x 4 = 56
14 x 5 = 70
14 x 6 = 84
14 x 7 = 98
14 x 8 = 112
14 x 9 = 126
14 x 10 = 140

Output 4:
Enter a number
10

Multiplication table for 10 is:

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

C Program To Print Multiplication Table Using While Loop


[youtube https://www.youtube.com/watch?v=-OfeGt8QV9s]

YouTube Link: https://www.youtube.com/watch?v=-OfeGt8QV9s [Watch the Video In Full Screen.]


Logic: Multiplication Table

We take a variable count and initialize it to 1 and keep increment the value of count by 1, until its value is 11. Once its value is 11 we stop iterating the while loop. This way we can calculate and out put multiplication table for 10 numbers.

Inside the while loop we multiply the user entered number and the value of count, and then display the result on each iteration.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *