Friday, 22 June 2012

write a c program to swap two number using bitwise operator


/* write a c program to swap two number using bitwise
operator*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nenter the two number :");
scanf("%d%d",&a,&b);
printf("\nthe value before swapping is :\na=%d\nb=%d",a,b);
a=a^b;
b=b^a;
a=a^b;
printf("\nafter swap :\na=%d\nb=%d\n",a,b);
getch();
}
/*
enter the two number :8 9

the value before swapping is :
a=8
b=9
after swap :
a=9
b=8
*/

No comments: