Arithmetic Operators Examples in C++


Description

These are the operators used to perform arithmetic/mathematical operations on operands. Examples: (+, -, *, /, %,++,–). Arithmetic operator are of two types:

  • Unary Operators: Operators that operates or works with a single operand are unary operators. For example: (++ , –)
  • Binary Operators: Operators that operates or works with two operands are binary operators. For example: (+ , – , * , /)

Example Program

Here is the simple program for Arithmetic Operators in C++.

Source Code Example : 1

#include<iostream>
using namespace std;
int main()
{
    int x,y;
    int sum;
    cout<<"Enter a number: ";
    cin>>x;
    cout<<"Enter another number: ";
    cin>>y;
    sum=x+y;
    cout<<"Sum is: "<<sum;
    return 0;
}
To download raw file Click Here

Output

Enter a number: 5
Enter another number: 4
Sum is: 9

Source Code Example : 2

#include<iostream>
using namespace std;
int main()
{
    int x,y;
    int diff;
    cout<<"Enter a number: ";
    cin>>x;
    cout<<"Enter another number: ";
    cin>>y;
    diff=x-y;
    cout<<"Difference is: "<<diff;
    return 0;
}
To download raw file Click Here

Output

Enter a number: 56
Enter another number: 23
Difference is: 33

Source Code Example : 3

#include<iostream>
using namespace std;
int main()
{
    int x,y;
    int product;
    cout<<"Enter a number: ";
    cin>>x;
    cout<<"Enter another number: ";
    cin>>y;
    product=x*y;
    cout<<"Product is: "<<product;
    return 0;
}
To download raw file Click Here

Output

Enter a number: 78
Enter another number: 34
Product is: 2652

Source Code Example : 4

#include<iostream>
using namespace std;
int main()
{
    int x,y;
    int div;
    cout<<"Enter a number: ";
    cin>>x;
    cout<<"Enter another number: ";
    cin>>y;
    div=x/y;
    cout<<"Division is: "<<div;
    return 0;
}
To download raw file Click Here

Output

Enter a number: 67
Enter another number: 3
Division is: 22

Basic Programs


Flow Control

IF Statement Examples


Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes