+ 1
Swap Numbers
how to swap two numbers without third variable
4 Respostas
+ 1
Thanks all for that :)
0
a=a+b
b=a-b
a=a-b
0
a, b = b, a
// Python
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