WAP to print table of any number using for loop

C program to print multiplication table of a given number

Write a C program to enter any 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

Logic to print multiplication table

Generating multiplication table isn't complex. What will take your mind is printing in the given format. So not wasting time let us get on to the logic of this program.
1.            Read number from user whose multiplication table is to be generated. Store it in some variable say num.
2.            Run a loop from 1 to 10, incrementing 1 on each repetition. The loop structure should look like for(i=1; i<=10; i++).
3.            Inside the loop generate multiplication table using num * i and print in given format. The sequence of printing multiplication table is num * i = (num * i)

Program to print multiplication table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
 * C program to print multiplication table of any number
 */

#include <stdio.h>

int main()
{
    int i, num;

    /* Read 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


Comments

Most Viewed

Write C program to enter any year and check whether year is leap year or not using conditional/ternary operator.

WAP to input week number and print week day name.

C Program to Find Third Angle of a Triangle