Sunday, 15 December 2013

C Program to Swap the Contents of two Numbers using Bitwise XOR Operation

#include < stdio.h>
 
void main()
{
    long i, k;
 
    printf("Enter two integers \n");
    scanf("%ld %ld", &i, &k);
    printf("\n Before swapping i= %ld and k = %ld", i, k);
    i = i ^ k;
    k = i ^ k;
    i = i ^ k;
    printf("\n After swapping i= %ld and k = %ld", i, k);
}

Output

 Enter two integers
 45 
 89 
 
Before swapping i =  45  and k =  89 
After swapping i =  89  and k =  45 

For More Details Please Visit Ictjobs.info

No comments: