C Language

Multiplication table of a number in given range using C

Multiplication table of a number in given range using C

In this article, we will discuss the concept of Multiplication table of a number in given range using C

In this program, we are going to learn how to generate a multiplication table using several ways in C language.

This is done using for loop , while loop , do-while loop and function in C language

Multiplication table of a number in given range using C using for loop

In this program, we will display multiplication table of a number in given range using for loop in C language

Program 1

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

int main()
{
    int i,num,range;
    printf("Enter the any number\n");
    scanf("%d",&num);
      printf("Enter the range\n");
    scanf("%d",&range);
    for(i=1; i<=range; i++){
        printf("%dx%d = %d\n",num,i,num*i);
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter the any number:
4
Enter the range:
8
4x1=4
4x2=8
4x3=12
4x4=16
4x5=20
4x6=24
4x7=28
4x8=32

 

  • integer variable num,i and range are declared.
  • The program asks input from the user
  • Then the user enters the input values for num and range
  • The program will read the input using Scanf() function and store to the variables num and range respectively
  • Create a for loop of i from 1 to 8 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using printf() function.

 

Multiplication table of a number in given range using C- using while loop

In this program, we will display multiplication table of a number in given range using while loop in C language

Program 2

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

int main()
{
    int i,num,range;
    printf("Enter the any number\n");
    scanf("%d",&num);
      printf("Enter the range\n");
    scanf("%d",&range);
    i=1;
    while(i<=range){
        printf("%dx%d = %d\n",num,i,num*i);
         i++;
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter the any number:
10
Enter the range:
12
10x1=10
10x2=20
10x3=20
10x4=40
10x5=50
10x6=60
10x7=70
10x8=80
10x9=90
10x10=100
10x11=110
10x12=120

 

  • integer variable num,i and range are declared.
  • The program asks input from the user
  • Then the user enters the input values for num and range
  • The program will read the input using Scanf() function and store to the variables num respectively
  • Create a while loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using printf() function.

 

Multiplication table of a number in given range using C- using do-while loop

In this program, we will display multiplication table of a number in given range using do-while loop in C language

Program 3

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

int main()
{
    int i,num,range;
    printf("Enter the any number\n");
    scanf("%d",&num);
      printf("Enter the range\n");
    scanf("%d",&range);
    i=1;
   do{
        printf("%dx%d = %d\n",num,i,num*i);
         i++;
    } while(i<=range);
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter the any number:
6
Enter the range:
8
6x1=6
6x2=12
6x3=18
6x4=24
6x5=30
6x6=36
6x7=42
6x8=48

 

  • integer variable num,i and range are declared.
  • The program asks input from the user
  • Then the user enters the input values for num and range
  • The program will read the input using Scanf() function and store to the variable num respectively
  • Create a do-while loop of i from 1 to 8 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using printf() function.

 

Multiplication table of a number in given range using C- using function

In this program, we will display multiplication table of a number in given range using function in C language

Program 4

#include <stdio.h>
#include <stdlib.h>
void mutipication_Table(int num, int range){//define the function
int count;
for(count=1; count<=range; count++){
    printf("%d x %d = %d\n",num,count,num*count);
}
}
int main()
{
    int num,range;
    printf("Enter a number: \n");
    scanf("%d",&num);
     printf("Enter the range: \n");
    scanf("%d",&range);
    mutipication_Table(num,range);//call the function
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter the a number:
8
Enter the range:
12
8x1=8
8x2=16
8x3=24
8x4=32
8x5=40
8x6=48
8x7=56
8x8=64
8x9=72
8x10=80
8x11=88
8x12=96

 

 

  • integer variable num,i and range are declared.
  • The program asks input from the user
  • Then the user enters the input values for num and range
  • The program will read the input using Scanf() function and store to the variable num and range respectively
  • Define the function  multipicationTable(int); to print multiplication table
  • Call the function to produce output
  • finally, the program displays the multiplication table using printf) function.

 

Suggested post

for loop in C language

while loop in C language

Do-while loop in C language

if statements in C language

Operator in C language

 

Similar post

Program to Display product of two numbers in Java

Program to Display product of two numbers in C

Program to Display product of two numbers in C++

Program to Display product of two numbers in Python

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.