Calculations

C++ program to multiply two numbers without using arithmetic operator

C++ program to multiply two numbers without using arithmetic operator

problem – C++  program to multiply two numbers without using arithmetic operator

 

In this tutorial, we will discuss the concept of  multiplying two numbers without using arithmetic operator in C++ language. 

In this post, we will learn how to get the product of two number without arithmetic operator in C++ programming language

 

multiply two numbers without using arithmetic operator

C++ program to find product of two numbers

Using for loop – Program 1

This program is used to find the multiplication of two numbers entered by the user – using for loop without arithmetic operator

#include <iostream>
#include <conio.h>
using namespace std;
int add(int n1, int n2);  //function prototype
int main()
{
    int n1,n2,product=0,i;
     cout << "Enter the first number: " ;
    cin>>n1;
    cout<<"Enter first  number: ";
    cin>>n2;
    for(i=0; i<n2; i++){
    product=add(product,n1); //function call
}
cout<<"product of "<<n1<<" and "<<n2<<" is: "<<product;
    getch();
    return 0;
}

int add(int num1,int num2){  //function definition
    int i;
for(i=0; i<num2; i++)
   num1++;
return num1;
    return 0;
}

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

Enter the first number: 32
Enter the second number: 5
Product of 32 and 5 is: 160

 

Using while loop – Program 2

This program is used to find the multiplication of two numbers entered by the user – using while loop without arithmetic operator

#include <iostream>
#include <conio.h>
using namespace std;
int add(int n1, int n2);//function prototype
int main()
{
    int n1,n2,product=0,i;  //variable declaration
     cout << "Enter the first number: " ;
    cin>>n1;   //takes input from user for n1
    cout<<"Enter the second number: ";
    cin>>n2;  //takes input from user for n2
    for(i=0; i<n2; i++){
    product=add(product,n1);//function call
}
cout<<"product of "<<n1<<" and "<<n2<<" is: "<<product;
    getch();
    return 0;
}

int add(int num1,int num2){  //function definition
    while(num2 != 0){
int num3=(num1 & num2);
num1=num1^num2;
num2=num3<<1;

}
return num1;
}

 

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

Enter the first number: 22
Enter the second number: 5
Product of 32 and 5 is: 110

 

Similar program

C++ find product of two numbers

Java program to multiply two numbers without using arithmetic operator

C program to multiply two numbers without using arithmetic operator

Python program to multiply two numbers without using arithmetic operator

 

Suggested for you

for loop in C++ language

while loop in C++ language

Datatype in C++ language

Variable in C++ language

Operator in C++ language

 

C program to multiply two numbers without using arithmetic operator
Java program to multiply of two numbers without using arithmetic operator
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago