C++ Program to Perform Addition Subtraction Multiplication Division

Here is a C++ program to add, subtract, multiply and divide two numbers. In this program, we will learn about basic arithmetic operators in C++ programming language.

Arithmetic operators in C++ are used to perform mathematical operations. There are five fundamental arithmetic operators supported by C++ language, which are addition(+), subtraction(-), division(/), multiplication(-), and modulus(%) of two numbers.

Operator Description Syntax Example
+ Adds two numbers a + b 15 + 5 = 20
- Subtracts two numbers a - b 15 - 5 = 10
* Multiplies two numbers a * b 15 * 5 = 75
/ Divides numerator by denominator a / b 15 / 5 = 3
% Returns remainder after an integer division a % b 15 % 5 = 0

C++ Program to Perform Addition Subtraction Multiplication Division of Two Numbers

#include <iostream>
using namespace std;

int main(){
    /* Variable declation */
    int x, y;
    int sum, difference, product, modulo;
    float quotient;
    // Taking input from user and storing it 
 // in x and y 
    cout << "Enter First Number\n";
    cin >> x;
    cout << "Enter Second Number\n";
    cin >> y;
    // Adding two numbers 
    sum = x + y;
    // Subtracting two numbers 
    difference = x - y;
    // Multiplying two numbers
    product = x * y;
    // Dividing two numbers by typecasting one operand to float
    quotient = (float)x / y;
    // returns remainder of after an integer division 
    modulo = x % y;
    cout << "\nSum = " << sum;
    cout << "\nDifference  = " <<difference;
    cout << "\nMultiplication = " << product;
    cout << "\nDivision = " << quotient;
    cout << "\nRemainder = " << modulo;
    return 0;
Enter First Number
Enter Second Number

Sum = 12
Difference  = 4
Multiplication = 32
Division = 2
Remainder = 0

In above program, we first take two numbers as input from user using cin and store it in variable x and y. Then we perform Addition, Subtraction, Multiplication, Division and Modulus on operands x and y and store the result in variable sum, difference, product, quotient and modulo respectively.

Recommended Posts
C++ Program to Find Sum of Natural Numbers
C++ Program to Count Zeros, Positive and Negative Numbers
C++ Program to Check Whether a Character is Vowel or Not
C++ Program to Multiply two Numbers
C++ Program to Calculate Average Percentage Marks
C++ Program to Find Quotient and Remainder
C++ Program to Find Size of Variables using sizeof Operator
C++ Program to Swap Two Numbers
C++ Program to Check Whether Number is Even or Odd
C++ Program to Find Largest of Three Numbers
C++ Program to Find LCM and GCD of Two Numbers
All C++ Programs