Cpp language uses operators to do arithmetic. Arithmetic Operator (AO) is a symbol that performs mathematical operation on data. C++ provides many arithmetic operators. Each of these operators uses two values (called operands) to calculate a final answer.
Arithmetic Operators
Cpp language uses operators to do arithmetic.Arithmetic Operator (AO) is a symbol that performs mathematical operation on data. C++ provides many arithmetic operators. Each of these operators uses two values (called operands) to calculate a final answer.
Following is list of all arithmetic operators in c++:
- Addition
- Subtraction
- Multiplication
- Division
- Modulus
Addition
The symbol use for addition is ‘+’. It is used to add two numbers in c++.
Example: 2+3 and result is 5.
Subtraction
The symbol use for subtraction in c++ is ‘-’. It is used to minus two numbers.
Example:4-1 ,Output is 3.
Multiplication
The symbol use for multiply two number and use ‘*’ symbol for multiplication in c++.
Division
The symbol use for Division in Cpp is ‘/’.
Example: 6/3 output is 2.
Modulus
The Modulus in c++ is used for gives the remainder of division of two integers. The symbol use for modulus is ‘%’.
Arithmetic operators program
I used Borland C++ compiler to run this program.
#include <iostream>
#include <conio>
int main ()
{
int a;
int b;
cout << " Enter two number for addition" << endl;
cin>> a;
cin>> b;
cout<<" the result is ="<<a+b<< endl;
cout << " Enter two number for subtraction" << endl;
cin>> a;
cin>> b;
cout<<" the result is ="<<a-b<< endl;
cout << " Enter two numbers for Multiplication " << endl;
cin>> a;
cin>> b;
cout<<" the result is ="<<a*b<< endl;
cout << " Enter two number for Division" << endl;
cin>> a;
cin>> b;
cout<< "the result is ="<< a/b;
getch ();
return 0;
}
arithmetic operators |
COMMENTS