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 |
8.In DSP,Define Signal and System?and various type of signals.
I am looking for selenium RC online Training in chennai. can any one tell me the best institute
write a query that returns one row for each department and the number of employees in that department. Given two tables EMPLOYEE and DEPARTMENT, where there can be multiple employees per department.
what is the certificates in biztalk?
what is the abap/4
Suppose i have all the implementation code required is written in doGet() but my class has doPost() method. i need code implemented in doGet() how can we do that?
What is the output of the following x = "abcdef" i = "a" for i in x: print(i), a) no output b) i i i i i i … c) a a a a a a … d) a b c d e f
difference between mantis and other tools?
what will we require to build project with the help of oracle
what is the basic and unique feature of dotnet
why not instantiating servet using new operator?
In staad pro, how can we design ROOF SLAB?