Public · Protected · Private
swapping two numbers
Type: Public  |  Created: 2008-09-01  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • int a = 8; int b = 9; swapping needs int temp = a; a= b; b= temp; Problem: how to avoid using an extra variable temp?
    2008-09-01 10:59
  • a = a+b; // a==8+9=17 b== 9 b = a-b; // a==17 b=17-9=8 a = a-b; // a==17-8=9 b==8
    2008-09-01 11:04
  • a = a-b; // a==8-9=-1 b== 9 b = b+a; // a==-1 b=9+(-1)=8 a = b-a; // a==8-(-1)=9 b==8 OR a= a*b; // a==8X9=72 b==9 b= a/b; // a==72 b=72/9=8 a= a/b; // a==72/8=9 b==8 OR a=a/b;.. ...... ...... OR a= a^ b;... b=log...... .......... OR ...... ....... .......
    2008-09-01 11:10
This blog is frozen. No new comments or edits allowed.