How to swap values between two variables without using a
third variable?
Answers were Sorted based on User's Feedback
Answer / chitra
main()
{
int a,b;
a=a+b;
b=a-b;
a=a-b;
}
chitra write answer
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / kumar
//language using C#
int a=10;
int b=20;
a=a+b;
b=a-b;
a=a-b;
thanks
Kumar
http://www.sourcecodehub.com/php/how-to-swap-values-of-two-variables-without-using-a-third-variable-integer/
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / nisay mizrahi
double a,b;
System.out.println("put in 2 numbers");
a=in.nextDouble();
b=in.nextDouble();
if(a>b){
a=a-b;
b=b+a;
a=b-a;
}
else
if(b>a){
b=b-a;
a=a+b;
b=a-b;
}
System.out.println("a is "+a);
System.out.println("b is "+b);
}
}
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / neha
class SwapBitwise
{
public void SwapByBitwise(int x, int y)
{
x =x ^ y;
y = x ^ y;
x = x ^ y;
System.out.println("x : " + x + " " + "y :" + y);
}
}
public class SwapOperation
{
public static void main(String[] args) {
SwapBitwise obj = new SwapBitwise();
obj.SwapByBitwise(200, 300);
}
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Need more information related to,
1. the values and type of variables before doing a swap, in
order to do the efficient memory management and code
robustness.
2.the reason to swap without using third variable.
3.code efficiency increased due to the two variable alone.
4.pre and post conditions for swap
5.the programming laguage to be used to do swap.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is %Type,%Rowtype?
Write a program to swap the content of two variables without using a third variable.
What is the language used for Artificial Intelligence?
Hey this is venkatesh.Please can any body tell me what is SFLNXTCHG?where we use this keyword?what perpuse we use this?Can you tell me in real time senario with example? And in 7 specification(RPG/400)what is the mandatory specification using programs?
What is the best action a system can take when deadlock is detected
hi, all this is shoba m.c.a . i have learned abap but no oppurtunities right now as fresher , right now i want to learn any course on demand any one pls suggest me good course and institute in hyderabad
Code for display the images from drive using vb 6.0?
When will you use shell script/Perl ahead of C/C++?
HTML is a subset of
hai i am prasanna.I am MCA 2009 fresher.tell me about certifications.which certification helps me to improve my carrier and to get a technically oriented job ,which certification helps to get job faster.
hi This is radhika.Can anyone help me to know the question papers of NATIONAL INFORMATICS CENTRE for the post of scientific officer/engineer? if anyone know plz tell me question paper pattern
I've an application where i need to give access to all the features only to admin and only few features to normal users. Say Menu...i dont want all my menu items to be accessible to all the users only the admin people can see few all the features where as normal users can have access to limited menu items...how can i achieve this. Please note that my menu is not a database driven menu.