Interview Questions   Tutorials   Discussions   Programs   Videos   

C++ - Why swapping program does not use third variable?




291
views
asked marvit August 18, 2014 12:39 PM  

Why swapping program does not use third variable?


           

1 Answers



 
answered By bhjahnavi   0  
/*program to swap two number with out using third variable */
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
cout<<"\n\nEnter the two no=:";
cin>>a>>b;
cout<<"\na"<<a<<"\nb"<<b;
a=a+b;
b=a-b;
a=a-b;

cout<<"\n\n a="<<a<<"\nb="<<b;
getch();
}
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert