Howdy readers, today you will learn **how to write a C program to generate a multiplication table**.

This tutorial takes an integer from the user, store the integer in a variable and then use a **for loop** to generate the multiplication table of the entered integer.

In this tutorial, we will be writing two programs. In the first program, the program will display the multiplication table up to **10**.

While in the second program, the program asks the user to enter a range, then it will display the multiplication table till the range specified by the user.

So, without any delay, let’s begin this tutorial.

**C Program to Generate Multiplication Table**

**C Program**

// C Program to Generate Multiplication Table #include <stdio.h> int main(){ int num; // Taking Input printf("Enter a positive integer: "); scanf("%d", &num); // Multiplication Table printf("Multiplication table of %d is: \n", num); for (int i = 1; i <= 10; i++){ printf("%d * %d = %d \n", num, i, num*i); } return 0; }

**Output**

Enter a positive integer: 7 Multiplication table of 7 is: 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

**Explanation**

int num;

We have declared an int data type variable **num**.

printf("Enter a positive integer: "); scanf("%d", &num);

The program takes an integer value from the user using the **scanf()** function. The integer is stored in the **num** variable.

for (int i = 1; i <= 10; i++){ printf("%d * %d = %d \n", num, i, num*i); }

Then, we used a **for loop** to print a multiplication table of **num** up to **10**.

The for loop iterates the loop from **i = 1** to **i = 10**. In each iteration of the loop, **num * i** is printed on the screen. After that, the iteration is incremented by **1**.

This loop keeps on executing until **i <= 10** condition becomes **False**.

**C Program to Generate Multiplication Table Up to a Range**

**C Program**

// C Program to Generate Multiplication Table Up to a Range #include <stdio.h> int main(){ int num, range; // Taking Input printf("Enter a number: "); scanf("%d", &num); do { printf("Enter the maximum value of the range (Positive integer): "); scanf("%d", &range); }while (range <= 0); // Multiplication Table printf("Multiplication table of %d till range %d is: \n", num, range); for (int i = 1; i <= range; i++){ printf("%d * %d = %d \n", num, i, num*i); } return 0; }

**Output**

Enter a number: 2 Enter the maximum value of the range (Positive integer): 15 Multiplication table of 2 till range 15 is: 2 * 1 = 2 2 * 2 = 4 2 * 3 = 6 2 * 4 = 8 2 * 5 = 10 2 * 6 = 12 2 * 7 = 14 2 * 8 = 16 2 * 9 = 18 2 * 10 = 20 2 * 11 = 22 2 * 12 = 24 2 * 13 = 26 2 * 14 = 28 2 * 15 = 30

**Explanation**

int num, range;

In this program, we have declared two int data type variables **num** and **range**.

printf("Enter a number: "); scanf("%d", &num);

The input is taken from the user. The input value is stored in the **num** variable.

do { printf("Enter the maximum value of the range (Positive integer): "); scanf("%d", &range); }while (range <= 0);

Then, we used a **do-while loop** to check whether the range entered by the user is positive or not. If the range is not positive, then the user is asked to enter the value of the range again.

This loop will keep on executing until the user enters a positive range.

Once a positive range is entered, this program will print the multiplication table of num.

for (int i = 1; i <= range; i++){ printf("%d * %d = %d \n", num, i, num*i); }

The **for loop** iterates the loop from **i = 1** to **i = range**. Within the loop, **n*i** is printed and iteration is incremented by **1**.

This loop keeps on executing till **i <= range** condition is True. If the **i <= range** condition becomes **False**, then the loop terminates, and the multiplication table is printed on the screen.

**Conclusion**

Today you learned **how to write a C program to generate a multiplication table**.

Besides that, you have also learned how to generate a multiplication table up to a certain range.

Now, you can calculate and print the multiplication table of any integer using the above logic.

If you have any queries related to the tutorial, Share your queries in the comment section.

Thanks for reading.

Happy Coding!!