# Multiplication table in C

This blog explores the use of C programming language to create multiplication tables using different methods, highlighting the importance of understanding these tables for developing strong mathematical skills and problem-solving abilities, while also providing insights into programming logic.

## Methods of Creating Multiplication Tables in C

Check out various methods to generate multiplication tables in C:

### Multiplication Table in C using For Loop

Go through below code for better understanding of Multiplication table in C using for Loop:

```//include standard input/output library
#include <stdio.h>

//main function
int main() {
//declare variables for number and counter
int num, i;

//prompt user to enter a number
printf("Enter a number: ");

//read input from user and store in variable num
scanf("%d", &num);

//use for loop to iterate from 1 to 10
for (i = 1; i <= 10; i++) {
//multiply num with current value of i and print the result
printf("%d x %d = %d\n", num, i, num * i);
}

//return 0 to indicate successful execution
return 0;
}```

Explanation of the code:

This C program generates a multiplication table for a specified number entered by the user.

1. User Input: The program prompts the user to enter a number using `printf()` and reads the input using `scanf()`, storing it in the variable `num`.

2. For Loop: It utilizes a `for` loop to iterate from 1 to 10, with `i` serving as the loop counter.

3. Multiplication Operation: Within the loop, the program computes the product of `num` and `i`, then prints the result in the format `”num x i = num*i”` using `printf()`.

4. Output: The multiplication table for the specified number is displayed in the console.

5. Return Statement: The `main()` function returns 0, indicating successful execution.

#### Output:

``Enter a number: 55 x 1 = 55 x 2 = 105 x 3 = 155 x 4 = 205 x 5 = 255 x 6 = 305 x 7 = 355 x 8 = 405 x 9 = 455 x 10 = 50``

### Multiplication Table in C using While Loop

Check out the below code of Multiplication table in C using While Loop:

```//include standard input/output library
#include <stdio.h>

//define main function
int main() {

//declare variables for input and counter
int num, i = 1;

//prompt user to enter a number
printf("Enter a number: ");

//read input from user and store in variable num
scanf("%d", &num);

printf("Multiplication table of %d:\n", num);

//while loop to print multiplication table
while (i <= 10) {

//calculate and print product of num and i
printf("%d x %d = %d\n", num, i, num * i);

//increment counter i by 1
i++;
}

//return 0 to indicate successful execution of program
return 0;
}```

Explanation of the code:

This C program generates a multiplication table for a specified number entered by the user using a while loop.

1. User Input: The program prompts the user to enter a number using `printf()` and reads the inpuxt using `scanf()`, storing it in the variable `num`.

2. Multiplication Table Heading: It prints the heading for the multiplication table indicating the number entered by the user.

3. While Loop: It utilizes a `while` loop with the loop counter `i` initialized to 1 and incremented by 1 in each iteration.

4. Multiplication Operation: Within the loop, the program calculates the product of `num` and `i`, then prints the result in the format `”num x i = num*i”` using `printf()`.

5. Output: The multiplication table for the specified number is displayed in the console.

6. Return Statement: The `main()` function returns 0, indicating successful execution.

#### Output:

``Enter a number: 7Multiplication table of 7:7 x 1 = 77 x 2 = 147 x 3 = 217 x 4 = 287 x 5 = 357 x 6 = 427 x 7 = 497 x 8 = 567 x 9 = 637 x 10 = 70``

### Multiplication Table in C using Do While Loop

Program of C of generating Multiplication table using Do While Loop code is given below:

```//include standard input/output library
#include <stdio.h>

//define main function
int main() {
//declare variables for input and counter
int num, i = 1;

//prompt user to enter a number
printf("Enter a number: ");

//read input from user and store in variable num
scanf("%d", &num);

printf("Multiplication Table of %d:\n", num);

//start do-while loop
do {
//calculate and print product of num and counter
printf("%d x %d = %d\n", num, i, num * i);

//increment counter by 1
i++;
}
//loop condition: counter should be less than or equal to 10
while (i <= 10);

//return 0 to indicate successful execution
return 0;
}```

Explanation of the code:

This C program generates a multiplication table for a specified number entered by the user using a do-while loop.

1. User Input: The program prompts the user to enter a number, which is read and stored in the variable `num` using `scanf()`.

2. Multiplication Table Heading: It prints the heading indicating the number entered by the user.

3. Do-While Loop: It executes a block of code that calculates and prints the product of `num` and the counter `i`, incrementing `i` each time.

4. Loop Condition: The loop continues as long as the counter `i` is less than or equal to 10.

5. Output: The multiplication table for the specified number is displayed in the console.

6. Return Statement: The `main()` function returns 0, indicating successful execution.

#### Output:

``Enter a number: 19Multiplication Table of 19:19 x 1 = 1919 x 2 = 3819 x 3 = 5719 x 4 = 7619 x 5 = 9519 x 6 = 11419 x 7 = 13319 x 8 = 15219 x 9 = 17119 x 10 = 190``

### Multiplication Table in C using Function

Code for Multiplication table in C using Function is mentioned here:

```//include standard input/output library
#include <stdio.h>

//define function for multiplication table
void multiplicationTable(int num) {
//declare variable for counter
int i;

//use for loop to iterate through numbers 1 to 10
for(i = 1; i <= 10; i++) {
//print the multiplication table for given number
printf("%d x %d = %d\n", num, i, num * i);
}
}

//main function
int main() {
//declare variable for input number
int num;

printf("Enter a number: ");
//store input in variable
scanf("%d", &num);

//call multiplicationTable function with input number as argument
multiplicationTable(num);

return 0;
}```

Explanation of the code:

This C program generates a multiplication table for a specified number entered by the user using a function.

1. Function Definition: The `multiplicationTable` function takes an integer parameter `num` and calculates the multiplication table for that number.

2. For Loop: Within the function, a `for` loop iterates from 1 to 10, calculating and printing the product of `num` and the loop counter.

3. User Input: In the `main` function, the user is prompted to enter a number, which is stored in the variable `num` using `scanf()`.

4. Function Call: The `multiplicationTable` function is called with the input number as an argument.

5. Output: The multiplication table for the specified number is displayed in the console.

6. Return Statement: The `main()` function returns 0, indicating successful execution.

#### Output:

``Enter a number: 2424 x 1 = 2424 x 2 = 4824 x 3 = 7224 x 4 = 9624 x 5 = 12024 x 6 = 14424 x 7 = 16824 x 8 = 19224 x 9 = 21624 x 10 = 240``

### Multiplication Table in C using Recursion

Learn how to make multiplication tables in C with a while loop. See the code below:

```//include necessary header files
#include <stdio.h>

//function to print multiplication table recursively
void multiplicationTable(int num, int count)
{
//base case
if(count > 10)
return;

//print the multiplication table
printf("%d x %d = %d\n", num, count, num*count);

//recursive call to print the next row
multiplicationTable(num, count+1);
}

//main function
int main()
{
//declare variables
int num;

//get input from user
printf("Enter a number: ");
scanf("%d", &num);

//call the function to print multiplication table
multiplicationTable(num, 1);

return 0;
}```

Explanation of the code:

This C program generates a multiplication table for a specified number entered by the user using recursion.

1. Function Definition: The `multiplicationTable` function recursively prints the multiplication table for the given number `num`. It takes two parameters: `num` (the number for which the multiplication table is generated) and `count` (the current row number).

2. Base Case: If `count` exceeds 10, indicating the end of the multiplication table, the function returns without further recursion.

3. Printing Multiplication Table: Within the function, the product of `num` and `count` is printed in the format `”num x count = num*count”`.

4. Recursive Call: The function calls itself with incremented `count` to print the next row of the multiplication table.

5. User Input: In the `main` function, the user is prompted to enter a number, which is stored in the variable `num` using `scanf()`.

6. Function Call: The `multiplicationTable` function is called with the input number and starting count as arguments.

7. Output: The multiplication table for the specified number is displayed in the console.

8. Return Statement: The `main()` function returns 0, indicating successful execution.

#### Output:

``Enter a number: 22 x 1 = 22 x 2 = 42 x 3 = 62 x 4 = 82 x 5 = 102 x 6 = 122 x 7 = 142 x 8 = 162 x 9 = 182 x 10 = 20``

Try out our Multiplication Calculator for faster results!

Understanding multiplication tables is important for getting better at math. Learning how to make them using C programming can help you think more logically. Trying out different ways to do it can make you better at both math and programming. It’s like a fun puzzle that helps you learn. So, by practicing different methods, you can get better at math and coding at the same time!

We hope our blog on “ Multiplication table in C”  was informative for you and provided useful insight about the Multiplication table in C Language. For more essential courses and blogs about C, C+, and Java keep checking our official Newtum website.