Program to Print Multiplication Table in C
Now that we understand what a multiplication table is & why it's important, let's create a program in C to generate these tables.
We'll start by looking at the basic structure of the program. We'll need to use nested loops to iterate through the rows & columns of the table. The outer loop will handle the rows, while the inner loop will handle the columns.
Here's a simple example of what the loop structure might look like:
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
// Print the product of i and j
}
// Move to the next row
}
In this example, we use two for loops. The outer loop uses the variable i to iterate from 1 to 10, representing the rows. The inner loop uses the variable j to iterate from 1 to 10, representing the columns.
Inside the inner loop, we'll need to print the product of i & j. After the inner loop finishes, we'll move to the next row.
In the following sections, we'll look at two specific ways to implement this:
- Using loops & without storing the results in an array
- Using loops & a 2-D array
1. Using loops & without storing them in an array
In this method, we'll use nested loops to generate the multiplication table on the fly, without storing the results in an array. Let’s see the code:
C
#include <stdio.h>
int main() {
int n = 10; // The size of the multiplication table
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
printf("%d\t", i * j);
}
printf("\n");
}
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
In this code :
- We include the stdio.h header for input/output operations.
- In the main() function, we declare a variable n to represent the size of the multiplication table. In this case, we set it to 10 for a 10x10 table.
- We start the outer loop, which iterates i from 1 to n. This represents the rows of the table.
- Inside the outer loop, we start the inner loop, which iterates j from 1 to n. This represents the columns of the table.
- Inside the inner loop, we use printf() to print the product of i & j. We use %d as the format specifier for integers & \t for a tab character to create space between the numbers.
- After the inner loop finishes, we use printf("\n") to move to the next line, starting a new row.
- The outer loop continues until all rows are printed.
Note: This method directly calculates & prints the product of each pair of numbers without storing them. It's a straightforward approach that's easy to understand.
2. Using loops & a 2-D array
In this method, we'll use nested loops to fill a 2-D array with the multiplication results. Once populated, the table is printed by accessing the array values. Let’s see the code:
C
#include <stdio.h>
int main() {
int rows, cols;
// Define the size of the table
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);
// Declare a 2D array to store the multiplication table
int table[rows][cols];
// Fill the 2D array using loops
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= cols; j++) {
table[i-1][j-1] = i * j; // Store the result of multiplication
}
}
// Print the multiplication table
printf("\nMultiplication Table:\n");
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= cols; j++) {
printf("%d\t", table[i-1][j-1]);
}
printf("\n");
}
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output
Enter the number of rows: 5
Enter the number of columns: 5
Multiplication Table:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
In this code :
- The program takes the number of rows and columns as input from the user.
- It uses two nested loops to populate a 2D array with the products of row and column indices.
- Another set of nested loops is used to print the multiplication table stored in the 2D array.
Frequently Asked Questions
Can I modify the code to display a multiplication table for numbers beyond 10?
Yes, you can adjust the loop conditions in the code to accommodate any range of numbers. Just ensure your array size matches the range you intend to display.
Why use a 2-D array for a multiplication table?
A 2-D array helps organize the data in a structured format, making it easier to access specific multiplication results and perform further operations like transposition or searching within the table.
What are the benefits of using loops without arrays for this program?
Using loops without arrays reduces memory usage, as no additional storage space is required. It's efficient for simple displays and when you don't need to retain the results after display.
Conclusion
In this article, we learned about multiplication tables & their importance in math education. We explained how to create a program in C to generate multiplication tables using loops. We looked at two methods: one without storing the results in an array & another using a 2-D array. We discussed the algorithms used in each method & analyzed their time & space complexity.