-->
Join Us on Facebook Follow us on Twitter Add to Circles

13 September 2013

Swapping the walue of two variable



#include<iostream>
   class interchange
   {
     private:
      int a1;
      int a2;
      int temp;


     public:
      void swap()
      {
        a1=5;
        a2=10;
        temp=a1;
        a1=a2;
        a2=temp;
      }
      void display()
      {
         cout<<"The new value of a1 is:"<<a1<<endl;
         cout<<"The new value of a2 is:"<<a2<<endl;
      }
   };
   void main()
   {
     interchange I1;
     I1.swap();
     I1.display();
   }

No comments:

Post a Comment