Arithmetic operators in C++
C++ arithmetic operators are used to carry out arithmetic or mathematical operations. These are addition, subtraction, multiplication, division, modulus, increment and decrement operators. Division operator returns quotient of any two values. Modulus operator returns division remainder of any two integer numbers. Increment operator increases the value by 1 while decrement operator decreases the value by 1.
The following program shows different arithmetic operation. ‘\n’ is used to print in the next line in the output screen.
#include<iostream>
using namespace std;
int main () {
int a, b, c;
cout<<"Enter any integer value ";
cin>>a;
cout<<"Enter any integer value ";
cin>>b;
// addition operator '+'
c = a+b;
cout<<"The addition of the two integer numbers is "<<c;
//substraction operator '-'
c = a-b;
cout<<"\nThe substraction of the two integer numbers is "<<c;
//multiplication operator '*'
c = a*b;
cout<<"\nThe multiplication of the two integer numbers is "<<c;
//division operator '/'
c = a/b;
cout<<"\nThe division of the two integer numbers is "<<c;
//modulus operator '%'
c = a%b;
cout<<"\nThe modulus of the two integer numbers is "<<c;
//increment operator '++'
cout<<"\nThe increment of integer a is "<<++a;
cout<<"\nThe increment of integer b is "<<++b;
//decrement operator '--'
cout<<"\n\nEnter any integer value ";
cin>>a;
cout<<"Enter any integer value ";
cin>>b;
cout<<"The decrement of integer a is "<<--a;
cout<<"\nThe decrement of integer b is "<<--b;
return 0;
}
Output:
Enter any integer value 12
Enter any integer value 5
The addition of the two integer numbers is 17
The substraction of the two integer numbers is 7
The multiplication of the two integer numbers is 60
The division of the two integer numbers is 2
The modulus of the two integer numbers is 2
The increment of integer a is 13
The increment of integer b is 6
Enter any integer value 8
Enter any integer value 6
The decrement of integer a is 7
The decrement of integer b is 5