#include<stdio.h>
void main()
{
int x = 10, y = 20;
printf("Before swap x=%d y=%d",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("
After swap x=%d y=%d",x,y);
}
//Author: Subodh
//! Swap two number using XOR operation
cout << "Before, n1 = " << num1 << ", n2 = " << num2 << endl;
num1 = num1 ^ num2, num2 = num1 ^ num2, num1 = num1 ^ num2;
cout << "After, n1 = " << num1 << ", n2 = " << num2 << endl;
#include <stdio.h>
int main()
{
int a, b, temp;
printf("enter the values of a and b:
");
scanf("%d%d", &a, &b );
printf("current values are:
a=%d
b=%d
", a, b);
temp=a;
a=b;
b=temp;
printf("After swapping:
a=%d
b=%d
", a, b);
}
#include <stdio.h>
int main()
{
int x = 20, y = 30, temp;
temp = x;
x = y;
y = temp;
printf("X = %d and Y = %d", x, y);
return 0;
}
// Overcomplicating things lol. Try this
#include <stdio.h>
int main()
{
int x, y;
printf("Enter Value of x ");
scanf("%d", &x);
printf("
Enter Value of y ");
scanf("%d", &y);
int temp = x;
x = y;
y = temp;
printf("
After Swapping: x = %d, y = %d", x, y);
return 0;
}