C program to swap two numbers using bitwise operators


#include<stdio.h>
#include<conio.h>
void main()
{
 int a, b;
 printf("n Enter values for a and b:");
 scanf("%d%d",&a,&b);
 printf("Before swapping: n");
 printf("a=%d, b=%d\n",a,b);
 a = a^b;
 b = a^b;
 a = a^b;
 printf("After swapping: n");
 printf("a=%d,b=%d\n",a,b); 
 getch();
} 

output:

Enter values for a and b: 10 20
Before swapping:
a=10, b=20
After swapping:
a=20, b=10

Leave a Reply

error: Content is protected !!
%d bloggers like this: