Swapping of two(2) numbers without using third variable?

Total Post:44

Points:310
C# 
C#
 573  View(s)
Ratings:
Rate this:
.
  1. Post:44

    Points:310
    Re: Swapping of two(2) numbers without using third variable?

    //Initialize two variables
    X=10 and Y=20  
    //Sum value of X & Y and assign into X  
    X=X+Y                  =10+20
    =30
    //Subtract Y from new value of X=30 and assign into Y
    Y=X-Y
    =30-20
    =10
    //Subtract new value of Y=10 from X=30 and assign into X
    X=X-Y
    =30-10
    =20
    FINAL VALUE OF X IS 20 AND Y IS 10
    (X=20 and Y=10)
     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!