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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.