Three Methods of C++ and C that would swap the 2 number.
Method 1:
Step 1 : a=a+b;
Step 2 : b = a-b;
Step 3 : a= a-b;
Example num1=5;num2=2;
Step 1 : num1 = (5+2) = 7
Step 2 : num2 =(7-2) = 5;
Step 3 : num1 = (7-5)= 2 ;
finally num1=2;num2=5;
Method 2 :
num2 = (num1*num1)/num1 + (num1=num2) - num1
Method 3:
num1^=num2^=num1^=num2;
try it!
Three Methods of swapping
Posted in
Sample C++ Program,
swap on C++,
Three Methods of swapping
Posted by
michel
on Thursday, October 15, 2009
at
11:20:00 PM
Subscribe to:
Post Comments (Atom)
3 comments:
dell drivers
just click here>>
http://www.getpcmemory.com/drivers/download-dell-optiplex-745-desktop-pc-windows-xp-vista-drivers/
webcam driver (LOGITECH)
http://www.howtodrivers.com/model41045.html
Yeng Constantino
(LAPIT)
http://www.starrecords.ph/album_details.asp?id=277
Post a Comment