Program to illustrate the use of Compound Assignment Operator

/* Program to illustrate the use of Compound Assignment Operator */
     # include <iostream.h>
     int main( )
     {            int n  = 22;
        cout <<"n = "<<n<<endl;
        n += 9 ;                            //adds 9 to n
        cout << "After n  + =  9 , n = " << n << endl ;
        n -= 5 ;                            // subtracts 5 from n
        cout << "After n  - =  5 , n = " << n << endl ;
        n *= 2 ;                            // multiplies n by 2
        cout << "After n  * =  2 , n = " << n << endl ;
        n /= 3 ;                            // divides n by 3
        cout << "After n  / =  3 , n = " << n << endl ;
        n %= 7 ;                     //reduces n to the remainder from dividing by 7
        cout << "After n  % =  7 , n = " << n << endl ;
              return 0;
      }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|