C Puzzle - 04
Swap two numbers using a logical operator
It is possible to swap two numbers without using a temporary variable and it is possible XOR operator.
The truth table of the XOR operator
Program
#include <stdio.h>
int main()
{
int a,b;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
printf("Before Sawp: a=%d.... b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("\nAfter Swap: a=%d.... b=%d",a,b);
return 0;
}
so useful mam!👏
ReplyDelete