C++ Program To Demonstrate Compound Operators

C++ Program To Demonstrate Compound Operators

Write C++ code to demonstrate the use of compound operators

// Write C++ code to demonstrate the use of compound operators.

#include <bits/stdc++.h>

using namespace std ;

int main()
{
    int a = 7, c;
    cout << "The value of a is : " << a ;

    c = a;    // c is 5
    cout << "\nc = a \t --> \t" ;
    cout << "c =" << c <<endl ;

    c += a;     //c = a + c
    cout << "\nc += a\t --> \t";
    cout << "c = "<< c <<endl;

    c -= a;     // c = c - a
    cout << "\nc -= a\t --> \t" ;
    cout<< "c = "<< c <<endl;

    c *= a;     // c = c * a
    cout << "\nc *= a\t --> \t";
    cout << "c =  " << c << endl;

    c /= a;     // c = c / a
    cout << "\nc /= a\t --> \t";
    cout << "c = "<< c << endl;

    c %= a;     // c = c % a
    cout << "\nc mode a --> \t";
    cout << "c = "<< c <<endl;

    return 0 ;
}

Output:

The value of a is : 7

c = a    -->    c =7
c += a   -->    c = 14
c -= a   -->    c = 7
c *= a   -->    c =  49
c /= a   -->    c = 7
c mode a -->    c = 0