In this article, you will learn the C++ program to divide multiply add, and subtract two numbers. The program takes two numbers from the user and displays the result on the screen.
If the user enters two numbers 10 and 2. The division, multiplication, addition, and subtraction of these two numbers will be 5, 20, 12, and 8 respectively.
Program: divide multiply add and subtract two numbers
#include<iostream>
using namespace std;
int main()
{
double num1, num2;
cout<<"Enter first Numbers: ";
cin>>num1;
cout<<"Enter second Numbers: ";
cin>>num2;
cout<<num1<<"+"<<num2<<" = "<<num1+num2<<endl;
cout<<num1<<"-"<< num2<<" = "<<num1-num2<<endl;
cout<<num1<<"*"<<num2<<" = "<<num1*num2<<endl;
cout<<num1<<"/"<<num2<<" = "<<num1/num2<<endl;
return 0;
}
Output
Description and working of this program
- Program asks the user to enter two numbers and store them in variables num1 and num2.
- Division of two numbers using the formula: division = num1/num2
- Multiplication of two numbers using the formula: multiplication = num1*num2
- Addition of two numbers using formula: addition = num1+num2
- Subtraction of two numbers using the formula: subtraction = num1-num2
- After the calculation display, all the results on the screen using the print statement
- End program