write a c++ program to input two numbers and display its sum, difference, multiplication, division and remainder with an appropriate message
Answers
#include <iostream>
using namespace std;
int main()
{
int first, second, add, subtract, multiply;
float divide;
cout << "Please enter two integer: ";
cin >> first;
cin >> second;
add = first + second;
subtract = first - second;
multiply = first * second;
divide = first / (float)second; //typecasting
cout << endl <<"Sum = " << add;
cout << endl <<"Difference = " << subtract;
cout << endl <<"Multiplication = " << multiply;
cout << endl <<"Division = " << divide;
return 0;
}
The C++ program is,
#include<iostream>
using namespace std;
int main(){
int a,b;
cout<<"Enter first number = ";
cin>>a;
cout<<"Enter second number = ";
cin>>b;
cout<<"Addition of "<<a<<" and "<<b<<" is "<<a+b<<".";
cout<<"\n\tDifference between "<<a<<" and "<<b<<" is "<<a-b<<".";
cout<<"\n\tMultiplication of "<<a<<" and "<<b<<" is "<<a*b<<".";
cout<<"\n\tDivision of "<<a<<" and "<<b<<" is "<<a/b<<".";
cout<<"\n\tRemainder after division of "<<a<<" and "<<b<<" is "<<a%b<<".";
return 0;
}
- It is a simple program for the given calculations in the question.
- Two inputs are taken or inputted into the variables a and b.
- After that, the given calculations are done inside the print statement.