In this program, you will learn how to swap two numbers. It is also know as swapping or exchange or interchange of two numbers. Here we will swap the two numbers without using third variable.
#include<stdio.h>
int main()
{
int a, b;
printf("Please enter the values of a and b: ");
scanf("%d%d", &a, &b);
printf("\nBefore swapping\n a = %d and b = %d", a, b);
a = a + b;
b = a - b;
a = a - b;
printf("\n\nAfter swapping\n a = %d and b = %d", a, b);
return 0;
}
Please enter the values of a and b: 54 96
Before swapping
a = 54 and b = 96
After swapping
a = 96 and b = 54