Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python program to Multiply two integers|in 5ways

Multiply two integers in C language|in 6ways

Posted on September 3, 2020September 6, 2020

Table of Contents

  • Multiply two integers in C language|6ways
    • Multiply two integers
      • Multiply two integers – standard method
      • Multiply two integers – using user input
      • Multiply two integers – using user defined function
      • Multiply two integers – using recursive function
      • Multiply two integers – using pointer
      • Multiply two integers – without multiplication operator
    • Related

Multiply two integers in C language|6ways

In this tutorial, we will discuss the Multiply two integers in C language

In this post, we are going to learn how to find multiplication of two numbers via different 6 ways in C language

Multiply two integers

Multiply two integers – standard method

Program 1

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

int main()
{
    int num1=10,num2=15,product;
    product=num1*num2;
    printf("product of %d and %d : %d",num1,num2,product);
    getch();
    return 0;
}

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

product of 10 and 15 : 150

 

Approach

  • Integer variable num1 and num2 both are declared and initialized
  • the num1 and num2 both are multiplied together and the value assigned to the integer variable product
  • finally the program is displayed the output using printf() function

 

Multiply two integers – using user input

Program 2

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

int main()
{
    int num1,num2,product;
    printf("Enter two numbers: ");
    scanf("%d %d",&num1,&num2);
    product=num1*num2;
    printf("product of %d and %d : %d",num1,num2,product);
    getch();
    return 0;
}

 

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

Enter two numbers:25
30
product of 25 and 30: 750

 

Approach

  • Integer variable num1 and num2 both are declared,
  • The program takes input from the user
  • Then the user enters the input value for num1 and num2
  • The program will read the input using scanf() function and store the variables in num1, num2.
  • The num1 and num2 both are multiplied together and the value assigned to the integer variable product
  • Finally the program is displayed the output using printf() function

 

Multiply two integers – using user defined function

Program 3

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

int main()
{
    int multiply(int,int),num1,num2,product;
    printf("Enter the first number!\n");
    scanf("%d",&num1);
    printf("Enter the second number!\n");
    scanf("%d",&num2);
    product=multiply(num1,num2);
    printf("Product of %d and %d is: %d",num1,num2,product);
    getch();
    return 0;
}

int multiply(int n1,int n2)
{
    return(n1*n2);
}

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

Enter the first number!
45
Enter the second number!
50
Product of 45 and 50 is: 2250

 

Approach

  • Declare a function named as multiply() with two int parameters
  • Declare num1,num2 and product.
  • The program takes input from the user
  • Then the user enters the input value for num1, num2
  • The program will read the input using scanf() function and store the variables in num1, num2 respectively
  • Define the function (multiply())for find product
  • Call the function to produce output
  • Finally, the program displays the result of multiplication using printf() function

 

Multiply two integers – using recursive function

Program 4

#include <stdio.h>
#include <stdlib.h>
int multiply(int,int);
int main()
{
    int num1,num2,product;
    printf("Enter the first number!\n");
    scanf("%d",&num1);
    printf("Enter the second number!\n");
    scanf("%d",&num2);
    product=multiply(num1,num2);
    printf("Product of %d and %d is: %d",num1,num2,product);
    getch();
    return 0;
}

int multiply(int n1,int n2)
{
    if(n2==1)
        return n1;
    else
        return(n1+multiply(n1,n2-1));
}


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

Enter the first number!
35
Enter the second number!
70
Product of 45 and 50 is: 2450

 

Approach

  • Declare a function named as multiply() with two int parameters
  • Declare num1,num2 and product.
  • The program takes input from the user
  • Then the user enters the input value for num1 and num2
  • the program will read the input using scanf() function and store the variables in num1, num2 respectively
  • define the recursive function (multipy())for find multiplication recursively
  • Call the function to produce output
  • finally, the program displays the result of multiplication using printf() function

 

Multiply two integers – using pointer

Program 5

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

int main()
{
    int num1,num2,*ptr1,*ptr2,multiple;

    //read two user input integer values for variable num1,num2
    printf("Enter first number\n");
    scanf("%d",&num1);

    printf("Enter second number\n");
    scanf("%d",&num2);

    ptr1=&num1;
    ptr2=&num2;
    //assign address of variable num1, num2 to pointers ptr1 and ptr2

    multiple=*ptr1 * *ptr2;
    printf("Product of the numbers %d and %d= %d",num1,num2,multiple);
    getch();
    return 0;
}

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

Enter first number!
15
Enter second number!
22
Product of the numbers 15 and 22 : 330

 

Approach

  • Integer variable num1 and num2 both are declared,
  • Integer pointer variable *ptr1 and *ptr2 both are declared,
  • The program takes input from the user
  • Then the user enters the input value for num1 and num2
  • The program will read the input using scanf() function and store the variables in num1, num2.
  • Addresses of num1 and num2 are assigned to variable ptr1 and ptr2 respectively
  • The pointer variables ptr1 and ptr2 both are use to multiply given numbers together and the value is assigned to the integer variable of multiple
  • Finally the program is displayed the output using printf() function

 

Multiply two integers – without multiplication operator

Program 6

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

int main()
{
    int num1,num2;//declaring two integer variable
    int product=0;//declaring and initializing product as zero

    printf("Enter two integer : \n");
    scanf("%d%d",&num1,&num2);
    //read the two input values from the user

    while(num2 != 0){
        product+=num1;
        num2--;
    }
    printf("\nProduct of two numbers= %d",product);
    getch();
    return 0;
}

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

Enter two integer:
12
13
product of two numbers=156

 

Suggested for you

Data type in C language

Variable in C language

Operator in C anguage

While loop in C language

 

Similar post

Find product of two numbers in Java language|5ways

Find product of two numbers in C++ language|6ways

Find product of two numbers in Python language|4ways

 

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes