y | z | y X-OR z |
---|---|---|
1 | 1 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
#include<stdio.h>
int main()
{
int a, b;
printf("\tEnter Two Numbers\n");
printf("----------------------------\n");
printf("Enter First Number : ");
scanf("%d", &a);
printf("\nEnter Second Number : ");
scanf("%d",&b);
printf("\nNumbers Before Exchange");
printf("\n----------------------------\n");
printf("a = %d and b = %d\n", a, b);
/* Swap Variables Using Bitwise Operator */
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("\nNumbers After Exchange");
printf("\n----------------------------\n");
printf("a = %d and b = %d", a, b);
return(0);
}