C program to generate multiplication table

devquora
devquora

Posted On: Jan 27, 2023

C program to generate multiplication table

 

Overview:

In this example, you will learn to generate the multiplication table of a number entered by the user up to the given range. Then, I will demonstrate an example of a multiplication table. After all, I will write the logic and C program to generate a multiplication table with output.

Table of contents:

  1. What is the multiplication table?
  2. Demonstration of the multiplication table
  3. Logic to generate multiplication table
  4. C program to generate multiplication table with output
  5. Conclusion

What is a multiplication table?

Multiplication table is a list of multiples of a particular number.

Demonstration of the multiplication table

 

multiplication table

Logic to generate multiplication table

  • Step 1: Input a number from the user to generate multiplication table. Store it in some variable say num.
  • Step 2: To print the multiplication table we need to iterate from 1 to 10.
  • Step 3: Run a loop from 1 to 10, increment 1 on each iteration.
  • Step 4: The loop structure should look like for(i=1; i<=10; i++).
  • Step 5: Inside loop generate multiplication table using num * i and print in the specified format.

C program to generate multiplication table

//Multiplication Table Up to 10
#include <stdio.h>
int main() {
    int n, i;
    printf("Enter an integer: ");
    scanf("%d", &n);
    for (i = 1; i <= 10; ++i) {
        printf("%d * %d = %d \n", n, i, n * i);
    }
    return 0;
}

The output of the Program with code:

When the above code is executed, it produces the following results:

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

Multiplication Table Output

//Multiplication Table Up to a range
#include <stdio.h>
int main() {
    int n, i, range;
    printf("Enter an integer: ");
    scanf("%d", &n);
    printf("Enter the range: ");
    scanf("%d", &range);
    for (i = 1; i <= range; ++i) {
        printf("%d * %d = %d \n", n, i, n * i);
    }
    return 0;
}

When the above code is executed, it produces the following results:

Enter an integer: 12

Enter the range: 8

12 * 1 = 12

12 * 2 = 24

12 * 3 = 36

12 * 4 = 48

12 * 5 = 60

12 * 6 = 72

12 * 7 = 84

12 * 8 = 96

Multiplication Table Output

Conclusion:

After the successful compilation of the program, In this program, we used two variables num, and i. The variable num is used to store the input integer number and the variable ‘i’ is used to iterate the loop. The product of the number is given by num*i;

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..