SWAP TWO NUMBERS USING BITWISE (XOR)

Consider the following I/O samples.




SAMPLE INPUT : 8000  200

SAMPLE OUTPUT:  200 8000




C PROGRAM:

#include <stdio.h>
int main()
{
    int a,b,t;
    scanf("%d %d",&a,&b);
    printf("\nBefore swapping : A = %d B = %d",a,b);

    a^=b;

             b^=a;

             a^=b; 

    printf("\nAfter swapping : A = %d B = %d",a,b);
    return 0;

}

 


OUTPUT:

 


  
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

 

Comments

Popular posts from this blog

HOLLOW INVERTED PYRAMID STAR

HOLLOW PYRAMID STAR PATTERN

INNER REDUCING PATTERN