| Author: Pascal 10 Jan 2009 | Member Level: Gold | Rating:  Points: 2 |
Here is the logic from my side.
a = b - a; b = b - a; a = a + b;
Console.WriteLine(a + ", " + b);
|
| Author: karthe 10 Jan 2009 | Member Level: Silver | Rating:  Points: 1 |
hi pascal,
thanks for ur reply. but its not working for few numbers. eg: a=13, b=7
could u help me
regards karthe
|
| Author: Gaurav Agrawal 10 Jan 2009 | Member Level: Diamond | Rating:  Points: 2 |
its working properly to verify use calculator with minus sign i think its a very good logic and if in ur application or coding this has been failed then can u tell us in which language and what cade u r using????
GA
Thanks & Regards,
Gaurav Agrawal Sr.Software Engineer gaur1982@yahoo.com 09829373514
|
| Author: Pascal 10 Jan 2009 | Member Level: Gold | Rating:  Points: 4 |
Hey,
Its working for me.. Here is the complete code. Copy this in Main function --------------------------- Console.WriteLine("Enter first number :"); int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second number :"); int b = Convert.ToInt32(Console.ReadLine()); SwapNumbers(a, b); Console.ReadLine();
Copy this outside main ---------------------- private static void SwapNumbers(int a, int b) { Console.WriteLine("After Swapping: "); a = b - a; b = b - a; a = a + b; Console.WriteLine(a + ", " + b); }
|
| Author: Sonia sardana 10 Jan 2009 | Member Level: Gold | Rating:  Points: 2 |
b=b-a a=b+a b=a-b
EX--Suppose a=18 b=65 b=65-18=47 a=47+18=65 b=65-47=18
UR Example--Suppose a=5 b=10 b=10-5=5 a=5+5=10 b=10-5=5
Reply if u got it.
|
| Author: Sonia sardana 10 Jan 2009 | Member Level: Gold | Rating:  Points: 1 |
ki karthe check mine reply its even working for numbers a=13, b=7 b=7-13=-6 a=-6+13=7 b=7-(-6)=13
|
| Author: Dhaval Shah 16 Jan 2009 | Member Level: Gold | Rating:  Points: 4 |
Its working for me.. Here is the complete code. Copy this in Main function --------------------------- Console.WriteLine("Enter first number :"); int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second number :"); int b = Convert.ToInt32(Console.ReadLine()); SwapNumbers(a, b); Console.ReadLine();
Copy this outside main ---------------------- private static void SwapNumbers(int a, int b) { Console.WriteLine("After Swapping: "); a = b - a; b = b - a; a = a + b; Console.WriteLine(a + ", " + b); }
Example :
b=b-a a=b+a b=a-b
EX--Suppose a=18 b=65 b=65-18=47 a=47+18=65 b=65-47=18
UR Example--Suppose a=5 b=10 b=10-5=5 a=5+5=10 b=10-5=5
Reply if u got it.
|
| Author: Julian 30 Jan 2009 | Member Level: Gold | Rating:  Points: 2 |
Hi,
The problem is when you minus the one number.
e.g. a = 7, b = 5.
a = b - a, then you will get a negative number.
So, just check which is the larger number and use that number to subtract and the solution will work :]....
|