C program to print multiplication table of a given number

Write a C program to input a number from user and print multiplication table of the given number using for loop. How to print multiplication table of a given number in C programming. Logic to print multiplication table of any given number in C program.

Example

Input

Input num: 5

Output

5 * 1  = 5
5 * 2  = 10
5 * 3  = 15
5 * 4  = 20
5 * 5  = 25
5 * 6  = 30
5 * 7  = 35
5 * 8  = 40
5 * 9  = 45
5 * 10 = 50

Required knowledge

Basic C programming, Arithmetic operators, Relational operators, For loop

Logic to print multiplication table

Step by step descriptive logic to print multiplication table.

  1. Input a number from user to generate multiplication table. Store it in some variable say num.
  2. To print multiplication table we need to iterate from 1 to 10. Run a loop from 1 to 10, increment 1 on each iteration. The loop structure should look like for(i=1; i<=10; i++).
  3. Inside loop generate multiplication table using num * i and print in specified format.

Program to print multiplication table

/**
 * C program to print multiplication table of a number
 */

#include <stdio.h>

int main()
{
    int i, num;

    /* Input a number to print table */
    printf("Enter number to print table: ");
    scanf("%d", &num);

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

    return 0;
}

Output

Enter number to print table of: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Happy coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.

Follow on: Facebook | Twitter | Google | or

Comments and discussion
Have a doubt, write here. I will help my best.
Before commenting you must escape your source code before commenting. Paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>