+ 1

Swap Numbers

how to swap two numbers without third variable

18th Dec 2016, 7:46 AM
Ashish Pandey
Ashish Pandey - avatar
4 odpowiedzi
+ 1
Thanks all for that :)
18th Dec 2016, 7:58 AM
Ashish Pandey
Ashish Pandey - avatar
0
a=a+b b=a-b a=a-b
18th Dec 2016, 7:51 AM
Vijeth Belle
Vijeth Belle - avatar
0
a, b = b, a // Python
18th Dec 2016, 7:52 AM
Rishi Anand
Rishi Anand - avatar
0
#include <iostream> using namespace std void main() {       int a,b;          cout<<"Enter value of a: ";     cin>>a;     cout<<"Enter value of b: ";     cin>>b;     a=a+b;     b=a-b;     a=a-b;     cout<<"After swap a: "<<a<<"b: "<<b;  } suppose a= 10; b = 5 a+ b = 15 =a a-b=5=b a-b =10 = a the output is a= 5 b=10 Hope I answered your question
18th Dec 2016, 7:56 AM
Mock
Mock - avatar