Write a C++ program that performs all compound assignment operations on an interger.

 


#include<iostream>

using namespace std;

int main()

{

int a;

a = 10;

cout<<"Value of a: "<<a<<endl;

a += 5;

cout<<"Value of a += 5: "<<a<<endl;

a -= 5;

cout<<"Value of a -= 5: "<<a<<endl;

a *= 2;

cout<<"Value of a *= 2: "<<a<<endl;

a /= 2;

cout<<"Value of a /= 2: "<<a<<endl;

a %= 2;

cout<<"Value of a %= 2: "<<a<<endl;

}

OUTPUT

Value of a: 10

Value of a += 5: 15

Value of a -= 5: 10

Value of a *= 2: 20

Value of a /= 2: 10

Value of a %= 2: 0


No comments:

Post a Comment