Arithmetic Operators in C++

Arithmetic Operators in C++
Techiio-author
Written by Sagar RabidasFebruary 6, 2022
7 min read
C++
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

In this blog, we will discuss Arithmetic Operators in C++.

Arithmetic Operators in C++

Mathematics operators are used to carrying out a few mathematical operations. Like some other operators, C++ additionally supports mathematics operators to carry out a few mathematical actions like addition, subtraction, multiplication, and so forth. In this newsletter, we are going to discuss the operators supported by the C++ language.

Top 7 Arithmetic Operators in C++

Below is the list of different operators explained in more detail.

  • Addition Operator (+): It is used to add two operands. Suppose X and Y are two operands, this plus operators will add up these two operands X + Y.
  • Subtraction Operator (-): It is used to subtract two operands. Suppose X and Y are two operands, then this minis operator will subtract the value of the second operand from the first operand.
  • Multiplication Operator (*): It is used to multiply two operands. Suppose X and Y are two operands then this multiplication operator will multiply X with Y.
  • Division Operator (/): It is used to numerator by the denominator. Suppose X and Y are two operands, this division operator divides the numerator by denominator.
  • Modulus Operator (%): It is used to give the remainder of the division. Suppose X and Y are two operands then this modulus operator first divides the numerator by denominator and gives the remainder.
  • Increment Operator (++): It is used to increment the value of the variable by 1. Suppose X is the operand, then this increment operator will add the value of X by 1.
  • Decrement Operator (–): It is used to decrementing the value of the variable by 1. Suppose X is the operand, this decrement operator will decrement the value of X by 1.

Examples of Arithmetic Operators in C++

Let’s discuss some examples to understand them in a better way.

Example #1 – Program to Use Addition (+) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X, Y, total;
cout << "Enter the value of X: ";
cin >> X;
cout << "Enter the value of Y: ";
cin >> Y;
total = X + Y;
cout << "Addition of X and Y is: " << total;
return 0;
}

Example #2 – Program to Use Subtraction (-) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X, Y, subtract;
cout << "Enter the value of X: ";
cin >> X;
cout << "Enter the value of Y: ";
cin >> Y;
subtract = X - Y;
cout << "Subtraction of Y from X is: " << subtract;
return 0;
}

Example #3 – Program to Use Multiplication (*) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X, Y, multiply;
cout << "Enter the value of X: ";
cin >> X;
cout << "Enter the value of Y: ";
cin >> Y;
multiply = X * Y;
cout << "Multiplication of X and Y is: " << multiply;
return 0;
}

Example #4 – Program to Use Division (/) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X, Y, divide;
cout << "Enter the value of X: ";
cin >> X;
cout << "Enter the value of Y: ";
cin >> Y;
divide = X/Y;
cout << "Division of X and Y is: " << divide;
return 0;
}

Example #5 – Program to Use Modulus (%) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X, Y, remainder;
cout << "Enter the value of X: ";
cin >> X;
cout << "Enter the value of Y: ";
cin >> Y;
remainder = X % Y;
cout << "Remainder of X and Y is: " << remainder;
return 0;
}

Example #6 – Program to Use Increment (++) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X;
cout << "Enter the value of X: ";
cin >> X;
X++;
cout << "Incremented value of X: " << X;
return 0;
}

Example #7 – Program to Use Decrement (–) Arithmetic Operator

Code:

#include <iostream>
using namespace std;
int main()
{
int X;
cout << "Enter the value of X: ";
cin >> X;
X--;
cout << "Decremented value of X: " << X;
return 0;
}

C
C++
Arithmetic Operators
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance