Print Multiplication Table of a Given Number in C
Printing a multiplication table is one of the most basic and important programs for beginners in C programming. It helps you understand user input, variables, loops, and formatted output.
In this tutorial, we will write a simple C program that takes a number from the user and prints its multiplication table.
1. Concepts Required
Before writing the program, you should understand the following basic concepts:
• Variables – To store the number entered by the user.
• Input/Output functions – scanf() and printf().
• Loops – To repeat the multiplication process (usually a for loop).
2. Algorithm
Step 1: Start the program.
Step 2: Declare variables (number and counter).
Step 3: Take input from the user.
Step 4: Use a loop from 1 to 10.
Step 5: Multiply the number with the loop counter.
Step 6: Print the result.
Step 7: Stop the program.
3. C Program Using for Loop
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Multiplication Table of %d:\n", num);
for(int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", num, i, num * i);
}
return 0;
}
4. Sample Output
If the user enters 5, the output will be:
Multiplication Table of 5: 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50
5. C Program Using while Loop (Alternative Method)
#include <stdio.h>
int main() {
int num, i = 1;
printf("Enter a number: ");
scanf("%d", &num);
printf("Multiplication Table of %d:\n", num);
while(i <= 10) {
printf("%d x %d = %d\n", num, i, num * i);
i++;
}
return 0;
}
6. Explanation of the Program
• #include
• int num; declares a variable to store the number entered by the user.
• scanf() takes input from the user.
• The loop runs from 1 to 10.
• num * i calculates the multiplication.
• printf() displays the formatted multiplication table.
Conclusion
Printing a multiplication table is a simple yet powerful beginner program in C. It helps you understand loops, arithmetic operations, and user input handling.
Practice modifying the program to print the table up to 20 or for multiple numbers to strengthen your basics.
Codecrown