Saturday, July 20, 2013

Swap two values using XOR in C Program

Swap values of two variables using XOR

#include<stdio.h>
#include<math.h>
int main()
{
 int a,b;
 printf("Enter the value of A : ");
 scanf("%d",&a);
 printf("\nEnter the value of b : ");
 scanf("%d",&b);
  a ^= b;
  b ^= a;
  a ^= b;

 printf("A : %d",a);
 printf("\nB : %d",b);
}

No comments:

Post a Comment