Codeforcoding

C program to create multiplication table

C program to create the multiplication table

In this tutorial, we will discuss the C program to create the multiplication table

We will learn how to create a multiplication table using loops. we can create multiplication table using for loop, while loop and do – while loop in C language.

Create multiplication table using for loop

In this program, the multiplication table is created using for loop in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int count,i;
    printf("Enter a number");
    scanf("%d",&count);
    printf("Here your multiplication table: \n");
    for(i=1; i<=12; i++){
        printf("%d * %d = %d \n",i,count,i*count);
    }
    getch();
    return 0;
}

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

Enter a number: 10
Here your multiplication table
1 * 10 = 10
2 * 10 = 20
3 * 10 = 30
4 * 10 = 40
5 * 10 = 50
6 * 10 = 60
7 * 10 = 70
8 * 10 = 80
9 * 10 = 90
10 * 10 = 100
11 * 10 = 110
11 * 10 = 120

 

Program 2

in this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int value,range,i;
    printf("Enter a integer value: ");
    scanf("%d",&value);
    printf("Enter a range: ");
    scanf("%d",&range);
    printf("Here your multiplication table: \n");
    for(i=1; i<=range; ++i){
        printf("%d * %d = %d \n",value,i, value*i);
    }
getch();
    return 0;
}

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

Enter the integer value: 10
Enter a range: 12

Here your multiplication table
10 * 1 = 15
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50
10 * 6 = 60
10 * 7 = 70
10 * 8 = 80
10 * 9 = 90
10 * 10 = 100
10 * 11 = 110
10 * 12 = 120

This multiplication is shown and explained using “x” mark

 

Create multiplication table using the while loop

In this program, the multiplication table is created using while loop in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int count,i;
    printf("Enter a number: ");
    scanf("%d",&count);
    printf("Here your multiplication table: \n");
    i=1;
    while(i<=10){
        printf("%d * %d = %d \n",i,count,i*count);
        i++;
    }

getch();
    return 0;
}

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

Enter a number: 10
Here your multiplication table
1 * 10 = 10
2 * 10 = 20
3 * 10 = 30
4 * 10 = 40
5 * 10 = 50
6 * 10 = 60
7 * 10 = 70
8 * 10 = 80
9 * 10 = 90
10 * 10 = 100
11 * 10 = 110

Program 2

This is a program for creating multiplication table user entered two positive integer value for their range to want  of multiplication table

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int value,range,i;
    printf("Enter a integer value: ");
    scanf("%d",&value);
    printf("Enter a range: ");
    scanf("%d",&range);
    printf("Here your multiplication table: \n");
    i=1;
    while(i<=range){
        printf("%d * %d = %d \n",value,i, value*i);
        i++;
    }

getch();
    return 0;
}


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

Enter the integer value: 15
Enter a range: 12

Here your multiplication table
15 * 1 = 15
15 * 2 = 30
15 * 3 = 45
15 * 4 = 60
15 * 5 = 75
15 * 6 = 90
15 * 7 = 105
15 * 8 = 120
15 * 9 = 135
15 * 10 = 150
15 * 11 = 165
15 * 12 = 180

This multiplication is shown and explained using “x” mark

 

Create multiplication table using the do-while loop

In this program, the multiplication table is created using do- while loop in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int count,i;
    printf("Enter a number ");
    scanf("%d",&count);
    printf("Here your multiplication table\n\n");
    i=1;
    do{
        printf("%d * %d = %d\n",i,count,i*count);
        i++;
    }while(i<=10);
    getch();
    return 0;
}

 

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

Enter a number 12
Here, your multiplication table

1 * 12 = 12
2 * 12 = 24
3 * 12 = 36
4 * 12 = 48
5 * 12 = 60
6 * 12 = 72
7 * 12 = 84
8 * 12 = 96
9 * 12 = 100
10 * 12 = 120

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int value,range,i;
    printf("Enter a integer value ");
    scanf("%d",&value);
    printf("Enter a range ");
    scanf("%d",&range);
    printf("Here your multiplication table\n\n");
    i=1;
    do{
        printf("%d * %d = %d\n",value,i,value*i);
        i++;
    }while(i<=range);
    getch();
    return 0;
}

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

Enter a integer value 12
Enter a range 10
Here your multiplication table

12*1=12
12*2=23
12*3=36
12*4=48
12*5=60
12*6=72
12*7=84
12*8=96
12*9=108
12*10=120

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

Another form of the multiplication table

Multiplication table using nested for loop

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j;
    printf("Multiplication table\n\n");
    printf("Here multiplication table\n\n");
    for(i=1; i<=10; i++){
        for(j=1; j<=10; j++){
                printf("%d\t", i*j);


    }
    printf("\n");
    }
    getch();
    return 0;
}

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

C program to create multiplication table
Multiplication table

This multiplication table is shown in the form of the table

Multiplication table using nested while loop

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i=1;
    printf("Multiplication table\n\n");
    printf("Here multiplication table\n\n");

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

    getch();
    return 0;

    }

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

Multiplication table

Multiplication table using the nested do-while loop

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j;
    i=1;
    printf("Multiplication table\n\n");
    printf("Here multiplication table\n\n");
 do{
    j=1;
 do{
    printf("%5d\t",i*j);
    j++;
 }while(j<=10);
    printf("\n");
    i++;
    }while(i<=10);
    getch();
    return 0;

    }

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

Multiplication table

 

Similar post

Multiplication table program in Java

Multiplication table program in Java using array

Multiplication table program in C

Multiplication table program in C++

Multiplication table program in Python

 

Suggested for you

For loop in Java language

For loop in C++ language

For loop in C language

For loop in Python language

 

While loop in Java language

While loop in C language

While loop in C++ language

While loop in Python language

 

Do-while loop in Java language

Do-while loop in C language

Do-while loop in C++ language

Java program to display multiplication table
Exit mobile version