C++ Arithmetic Operators

Arithmetic operators


  • Arithmetic operators are used for Arithmetic Calculation.
  • These are used to perform mathematical calculations like addition (+), subtraction(-), multiplication (*), division (/), and modulus (remainder) (%).
Example :

#include<iostream>
using namespace std;
int main()
{
    int num1,num2;
    int add,subs,mul,div,mod;

    cout<<"\nEnter First Number :";
    cin>>num1;

    cout<<"\nEnter Second Number :";
    cin>>num2;

    // (+) operator
    add = num1 + num2;
    cout<<"\nAddition is : "<<add;

    // (-) operator
    subs = num1 - num2;
    cout<<"\nSubtraction is : "<<subs;

    // (*) operator
    mul = num1 * num2;
    cout<<"\nMultiplication is : "<<mul;

    // (÷) operator
    div = num1 / num2;
    cout<<"\nDivision is : "<<div;

    // (%) operator
    mod = num2 % num1;
    cout<<"\nModulus is : "<<mod;

    return 0;
}
Output
    Enter First Number : 10
    Enter Second Number : 2
    Addition is : 12
    Subtraction is : 8
    Multiplication is : 20
    Division is : 5
    Modulus is : 2


0 Comments