Pages

Saturday, July 06, 2013

Write a program that calculate compound assignment in C++

Demonstrate the example of Compound Assignment

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    #include <iostream.h>
    #include <conio.h>
    int main()
    {  
    int x = 10;
    int y =  5;
    cout << "Demonstrate tha example of Compound Assignment\n";
    cout << "\tEnter two integer values?\n";
    cout << " x: " << x << "     | " << "y: " << y <<"     |"<<" ( x *=y): " << (x *=y) ;
    cout << "   | x is now:"<< x << "\n";
    x=10;
    cout << " x: " << x << "     | " << "y: " << y <<"     | "<<" (x /=y): " << (x /=y) ;
    cout << "   | x is now:"<< x << "\n";
    x=10;
    cout << " x: " << x << "     | "<<"y: " << y <<"     | "<<" (x %=y): " << (x %=y) ;
    cout << "   | x is now:"<< x << "\n";
    getch();
    return 0;
            }//main

Output:

Demonstrate tha example of Compound Assignment
 Enter two Integer Values?
 x: 10   | y: 5 | (x *=y): 50 | x is now: 50
 x: 10   | y: 5 | (x /=y): 2  | x is now: 2
 x: 10   | y: 5 | (x *=y): 0  | x is now: 0

No comments:

Post a Comment