Table of Contents
In this tutorial, we will discuss the C++ program to multiply of two numbers
In this post, we are going to learn how to find multiplication of two numbers via different 6 ways in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int num1=50,num2=20, product; product=num1*num2; cout << "Product of "<<num1<<" and "<<num2<<" is :"<< product<<endl; getch(); return 0; }
When the above code is executed, it produces the following result
Product of 50 and 20 is: 1000
In this program,
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int num1,num2; cout<<"Enter two numbers: "; //The program ask to enter two numbers cin>>num1>>num2; //store two integer numbers in variable num1 and num2 respectively //performs multiplication and stores the result in variable product int product=num1*num2; cout << "Product of "<<num1<<" and "<<num2<<" is :"<< product<<endl; //display the product of two numbers getch(); return 0; }
When the above code is executed, it produces the following result
Enter two numbers 24 12 product of 24 and 12 is: 288
in this program,
Program 3
#include <iostream> #include <conio.h> using namespace std; int multiply(int x, int y);//function prototype int main() { int num1,num2; cout<<"Enter two numbers: "; //The program ask to enter two numbers cin>>num1>>num2; //store two integer numbers in variable num1 and num2 respectively //performs multiplication and stores the result in variable product int product=multiply(num1,num2); cout << "Product of "<<num1<<" and "<<num2<<" is :"<< product<<endl; //display the product of two numbers getch(); return 0; } int multiply(int x, int y) { return(x*y);//return the result to main }
When the above code is executed, it produces the following result
Enter two numbers 40 30 product of 40 and 30 is: 1200
Approach
Program 4
#include <iostream> #include <conio.h> using namespace std; int multiply(int,int);//function prototype int main() { int num1,num2; cout<<"Enter two numbers: "; //The program ask to enter two numbers cin>>num1>>num2; //store two integer numbers in variable num1 and num2 respectively //performs multiplication and stores the result in variable product int product=multiply(num1,num2); cout << "Product of "<<num1<<" and "<<num2<<" is :"<< product<<endl; //display the product of two numbers getch(); return 0; } int multiply(int x, int y) { if(x<y){ return multiply(y,x); } else if(y!=0){ return(x+multiply(x,y-1));//return the result to main } else { return 0; } }
When the above code is executed, it produces the following result
Enter two numbers 23 34 product of 40 and 30 is: 782
Program 5
#include <iostream> #include <conio.h> using namespace std; int main() { int num1,num2,mul; int *ptr1,*ptr2; cout<<"Enter two numbers: "; //The program ask to enter two numbers cin>>num1>>num2; //store two integer numbers in variable num1 and num2 respectively //performs multiplication and stores the result in variable product ptr1=&num1; ptr2=&num2; mul=*ptr1 * *ptr2; cout << "Product of "<<num1<<" and "<<num2<<" is :"<< mul<<endl; //display the product of two numbers getch(); return 0; }
When the above code is executed, it produces the following result
Enter two numbers 54 43 product of 40 and 30 is: 2322
Program 6
#include <iostream> #include <conio.h> using namespace std; int main() { int num1,num2,product=0; cout << "Enter two numbers for multiply" << endl; cin>>num1>>num2; for(int i=1; i<=num2; i++){ product=product+num1; } cout<<"The product of "<<num1<<" and "<<num2<<" is :"<<product<<endl; getch(); return 0; }
When the above code is executed, it produces the following result
Enter two numbers for multiply 25 35 The product of 25 and 35 is: 875
Suggested for you
Data type in C++ language
Variable in C++ language
Similar post
Find product of two numbers in Java language|5ways
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.