Skip to content

Instantly share code, notes, and snippets.

@Zulqurnain
Created September 18, 2013 14:57
Show Gist options
  • Save Zulqurnain/6610394 to your computer and use it in GitHub Desktop.
Save Zulqurnain/6610394 to your computer and use it in GitHub Desktop.
Swap two variables without using third variable. C/ C++
#include <iostream.h>
int main(){
int x=1,y=2;
cout<<"x :=:"<<x<<"\ny :=:"<<y<<"\n";
x+=y;
y=x-y;
x-=y;
cout<<"\nx :=:"<<x<<"\ny :=:"<<y<<"\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment