Wednesday, November 6
Swapping without use of third variable
23:14
By
Unknown
swapping in three steps
,
swapping using multiplication operator
,
swapping variables without another variable
8
comments
Swapping means to interchange values of usually two variables and is done using third temp variable e.g.
But take a look at code swapping without use of third variable, this trick will come handy in future assignments
For the person who can explain this code to me and post a solution using (^) operator, there is a GENUINE MICROSOFT VISUAL STUDIO KEY ;)
You can post a request for guest post in comments, anywhere
int var1 = 10, var2 = 20; int temp = var2; var2 = var1; var1 = temp; //now var1 = 20 and var2 = 10 //hence values have been swapped
But take a look at code swapping without use of third variable, this trick will come handy in future assignments
int var1 = 10, var2 = 20; var1 = var1 * var2; var2 = var1 / var2; var1 = var1 / var2; //now var1 = 20 and var2 = 10 //hence values have been swapped
For the person who can explain this code to me and post a solution using (^) operator, there is a GENUINE MICROSOFT VISUAL STUDIO KEY ;)
You can post a request for guest post in comments, anywhere
great man (y)
ReplyDeletekeep it up :)
here you go man..
ReplyDeletehere is how to swap with additions
ReplyDeleteint a,b;
a=a+b;
b=a-b;
a=a-b;
simple
Addition : var1 = var1 + var2;
ReplyDeleteSubtraction : var2 = var1 - var2;
yara addition and subtraction wala code bhi share karo
ReplyDelete@Saad Abdullah Munir please paste code in comment or mail it to fmswwx@gmail.com and we will get it posted
ReplyDeletegreat yaar please share the code with us, you will get a special referral on post
ReplyDeletei have done this program but using addition and subtraction logic..
ReplyDelete