Arithmetic Operators Examples in C++


Arithmetic operators in C++ are operators that perform basic mathematical operations such as addition, subtraction, multiplication, and division on numerical data types.

C++ provides the following arithmetic operators:

  • Addition Operator (+): Adds two operands.
  • Subtraction Operator (-): Subtracts one operand from another.
  • Multiplication Operator (*): Multiplies two operands.
  • Division Operator (/): Divides one operand by another.
  • Modulus Operator (%): Returns the remainder of a division operation.
  • Increment Operator (++): Adds 1 to the operand.
  • Decrement Operator (--): Subtracts 1 from the operand.

Arithmetic operators can be used with various data types in C++, including integers, floating-point numbers, and characters. These operators are used extensively in mathematical calculations in C++ programs.

The examples provided in my previous response demonstrate the usage of these arithmetic operators with integer data types 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

Program List


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


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples