In this method, we will calculate the sum of two given numbers and assign one of them. The numbers can then be swapped using the subtraction from the sum.
#include <stdio.h>
int main()
{
int a = 10, b = 20;
a = a + b; // a now becomes 30
b = a - b; // b becomes 10
a = a - b; // a becomes 20
printf("After Swapping: a = %d, b = %d", a, b);
return 0;
}
Output:
Enter Value of a = 10
Enter Value of b = 20
After Swapping: a = 20, b = 10
need an explanation for this answer? contact us directly to get an explanation for this answer