Swap two variables without using third variable in C

There are many ways to do this:-
 
Solution: 1
 
void main(){
    int x,y;
    scanf("%d%d",&x,&y);
    //swapping
    x=x+y;
    y=x-y;
    x=x-y;
    printf("%d %d",x,y);
}
 
Solution: 2
 
void main(){
    int x,y;
    scanf("%d%d",&x,&y);
    //swapping
    x=x^y;
    y=y^x;
    x=x^y;
    printf("%d %d",x,y);
}

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Migrating database from ASP.NET Identity to ASP.NET Core Identity