Input Two Numbers And Apply Arithmetic Operations in CPP
- Home
- Tutorials
- CPP
- CPP Programs
- Input Statement
- Program
Source Code
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
// Declaration of Two Variables
int a,b;
// Getting Input in Variables
cout<<"Enter First Number: ";
cin>>a;
cout<<"Enter Second Number: ";
cin>>b;
// Additon
cout<<" A + B = "<<a+b;
// Subtraction
cout<<"\n A - B = "<<a-b;
// Multiplication
cout<<"\n A * B = "<<a*b;
// Division
cout<<"\n A / B = "<<a/b;
// Remainder
cout<<"\n A % B = "<<a%b;
return 0;
}
Output
Working
This program perform five basic arithmetic operation on input. These operations include
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Remainder
First two variables a and b of type int are declared.Then take input in these variables using cin statement. cout statement is used to display message about input to be taken. These two inputs can also be taken using single cin statement as follow.
cout<<"Enter Two Values : ";
cin>>a>>b;
After getting input all operations are performed in cout statement.