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 |
1.What is difference between symget and & in sas? 2.what is difference between callsymput and %let?
3.Give the formula for determine the range of the data type?
How to print a name "ARCHANA" in any programming language
how many logical drive we can form to physical device in our computer?
Suppose server object is not loaded into the memory, and the client request for it , what will happen?
SAS question: I have 50 fils a1,a2,...,a50. the primary key is upc. then if i want to merge all 50 files, the code is as follows, data test; merge a1 ... a50; by upc; run; we know that writing all 50 files name is time consuming, is there any standard format of this code?
I want Ada programming language books. Could anyone post me any link for that?
how many types of operating system are avaliable?
What are data structures?
hi friends i am ravi here , i have one problem at starting at the interview that is i have my 3+ it(java) years experiance profile so if i attend the interview interviewer ased me tel me about your profile so i not able to explain because i dont knw where to start and where to end and i dont know what i should tel and what i shouldnot tel .....so can any body please clear m doubts clearly.............please help me friends,i am awaiting for friends reply please.............
hoe to data grid use in sql server 2000?
Write a pascal program to calculate the sum of the first 100 even number and odd number