0

a program to swap to numbers !!

without using third variable as well as array

20th Aug 2016, 7:00 AM
Asim
Asim - avatar
4 Réponses
+ 3
#include<iostream> int main() { int a,b; cout<<"enter two numbers"; cin>>a>>b; a+=b; b=a-b; a-=b; cout<<"after swapping \n"; cout<<"a="<<a<<"b=<<"b; return 0; }
20th Aug 2016, 8:09 AM
Muhammed cp
Muhammed cp - avatar
+ 3
int a = 1; int b = 2; swap (a,b); cout <<a <<b; outputs 21 without a 3rd variable and an array as u asked
20th Aug 2016, 3:56 PM
Sardor
Sardor - avatar
0
You can use simple logic int a,b; a=a+b; b=a-b; a=a-b; for ex if a=4 and b=5 a=4+5; b=9-5; a=9-4;
20th Aug 2016, 12:19 PM
Aayush Rawat
Aayush Rawat - avatar
0
Hello ayush, Same procedure is I used above...
20th Aug 2016, 2:27 PM
Muhammed cp
Muhammed cp - avatar