Arithmetic Operators


Arithmetic Operators: Arithmetic operators provide operators for five basic arithmetic calculations :
1. Addition
2. Subtraction
3. Multiplication
4. Division and
5. Remainder

Each of these operators is binary operator i.e, it requires two values (operands) to calculate a final answer.

1.Addition : Gives the addition of two valid inputs.

Example:
#include<iostream.h>
void main()
{
    int a;
    int b;
   
    cout<<"Enter integer a = ";
    cin>>a;
   
    cout<<"Enter integer b = ";
    cin>>b;
   
    cout<<"Addition of a and b = ";
    cout<<a+b;
}

Output :
Enter integer a = 15
Enter integer b = 5;
Addition of a and b =20


1.Subtraction: Gives the subtraction of two valid inputs.

Example:
#include<iostream.h>
void main()
{
    int a;
    int b;
   
    cout<<"Enter integer a = ";
    cin>>a;
   
    cout<<"Enter integer b = ";
    cin>>b;
   
    cout<<"Subtraction of a and b = ";
    cout<<a-b;
}

Output :
Enter integer a = 15
Enter integer b = 5;
Subtraction of a and b =10


1.Multiplication: Gives the multiplication of two valid inputs.

Example:
#include<iostream.h>
void main()
{
    int a;
    int b;
   
    cout<<"Enter integer a = ";
    cin>>a;
   
    cout<<"Enter integer b = ";
    cin>>b;
   
    cout<<"Multiplication of a and b = ";
    cout<<a*b;
}

Output :
Enter integer a = 15
Enter integer b = 5;
Multiplication of a and b =75


1.Division: Gives the division i.e quotient of two valid inputs.

Example:
#include<iostream.h>
void main()
{
    int a;
    int b;
   
    cout<<"Enter integer a = ";
    cin>>a;
   
    cout<<"Enter integer b = ";
    cin>>b;
   
    cout<<"Division of a and b = ";
    cout<<a/b;
}

Output :
Enter integer a = 15
Enter integer b = 5;
Division of a and b =3


1.Remainder/Modulus: Gives the remainder of two valid inputs.
example:
#include<iostream.h>
void main()
{
    int a;
    int b;
   
    cout<<"Enter integer a = ";
    cin>>a;
   
    cout<<"Enter integer b = ";
    cin>>b;
   
    cout<<"Remainder of a and b = ";
    cout<<a%b;
}

Output :
Enter integer a = 15
Enter integer b = 5;
Remainder of a and b =0



Post a comment

0 Comments