Print multiplication table in C
In this article, you will learn how to write a C program to print multiplication table. Such a type of question is generally asked in programming interviews.
C multiplication table using for loop
Here, we have used the for loop to print multiplication table. First, we have taken the input number from the user. Then we have iterated 10 times using the for loop. In the initial iteration, the loop iterates and multiplies by 1 the given number. In the second iteration, 2 is multiplied by the given number, and so on.
#include <stdio.h>
int main() {
int num, i;
printf("Enter an integer: ");
scanf("%d", &num);
for (i = 1; i <= 10; ++i) {
printf("%d * %d = %d \n", num, i, num * i);
}
return 0;
}
Output of the above code:
Enter an integer: 7
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
Enter an integer: 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
C multiplication table using while loop
In the given program, we have used the while loop to print the multiplication table in C. We have declared a variable i and initialized it by 1. Next, we will iterate the while loop until the value of i is smaller and equal to 10. In each iteration, the value of i is incremented by one and multiplied by the num variable. The loop is terminated when the value of i becomes greater than 10.
#include <stdio.h>
int main() {
int num, i=1;
printf("Enter an integer: ");
scanf("%d", &num);
while (i<=10){
num = num * 1;
printf("%d * %d = %d \n", num, i, num * i);
i += 1 ;
}
return 0;
}
Output of the above code:
Enter an integer: 15
15 * 1 = 15
15 * 2 = 30
15 * 3 = 45
15 * 4 = 60
15 * 5 = 75
15 * 6 = 90
15 * 7 = 105
15 * 8 = 120
15 * 9 = 135
15 * 10 = 150
C multiplication table using do-while loop
In the given C program, we have used the do-while loop to print the multiplication table.
#include <stdio.h>
int main() {
int num, i = 1; // declare a variable
printf ("Enter a number: ");
scanf ("%d", &num);
do
{
printf ("%d * %d = %d \n", num, i, (num * i));
i++; // incremented by 1
} while (i <= 10);
return 0;
}
Output of the above code:
Enter a number: 24
24 * 1 = 24
24 * 2 = 48
24 * 3 = 72
24 * 4 = 96
24 * 5 = 120
24 * 6 = 144
24 * 7 = 168
24 * 8 = 192
24 * 9 = 216
24 * 10 = 240
C multiplication table using recursion function
Recursion function is a function that is called by itself. Here is the C program to print the multiplication table using the recursion function.
#include <stdio.h>
int main()
{
int num, i = 0;
printf("Enter a number: ");
scanf(" %d", &num);
printf("\nTable of %d :", num);
// calling function
multiplication_table(num, 1);
}
// definition of multiplication_table()
void multiplication_table(int num, int i)
{
printf("\n");
printf("%d * %d = %d ", num, i, (num * i));
if (i < 10)
return multiplication_table(num, i + 1);
}
Output of the above code:
Enter a number: 23
Table of 23 :
23 * 1 = 23
23 * 2 = 46
23 * 3 = 69
23 * 4 = 92
23 * 5 = 115
23 * 6 = 138
23 * 7 = 161
23 * 8 = 184
23 * 9 = 207
23 * 10 = 230
C multiplication table using pointer
In the given C program, we use the pointer to print the multiplication table.
#include <stdio.h>
int main ()
{
// declare integer variables
int num, i;
// integer pointer variable
int *ptr;
printf ("Enter a number: ");
scanf ("%d", &num);
ptr = #
printf ("\nTable of %d: \n", num);
for( i = 1; i <= 10; i++)
{
printf ("%d * %d = %d \n", num, i, (num*i));
}
return 0;
}
Output of the above code:
Enter a number: 19
Table of 19:
19 * 1 = 19
19 * 2 = 38
19 * 3 = 57
19 * 4 = 76
19 * 5 = 95
19 * 6 = 114
19 * 7 = 133
19 * 8 = 152
19 * 9 = 171
19 * 10 = 190
C Program to Print Multiplication Table from 1 to 10
In the given C program, we print the multiplication table from 1 to 10 using for loop.
#include
int main ()
{
// declare integer variables
int i, j;
int num1 = 1, num2=10;
for (i = num1; i <= num2; i++)
{
num1 = i;
// inner for loop
printf ("Table of %d => ", num1);
for (j = 1; j <=10; j++)
{
printf("%3d |", num1 * j);
}
printf (" \n");
}
}
Output of the above code:
Table of 1 => 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
Table of 2 => 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
Table of 3 => 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |
Table of 4 => 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |
Table of 5 => 5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
Table of 6 => 6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |
Table of 7 => 7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |
Table of 8 => 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |
Table of 9 => 9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
Table of 10 => 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to find area of rectangle
C program to convert celsius to fahrenheit
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to calculate compound interest
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative