A Program to Swap Fixed Value Without 3rd Variable
In this example, we are giving a program to swap fixed value without using the 3rd variable.
Program to to swap fixed value without the 3rd variable:
#include <stdio.h>
#include <conio.h>
int main() {
int a = 10, b = 20;
// code to swap 'a' and 'b'
a = a + b; // a now becomes 30
b = a - b; // b becomes 10 and getting new value of b
a = a - b; // a becomes 20 and getting new value of a
printf("After swapping: a = %d, b = %d", a, b);
return 0;
}
Output:
After swapping: a = 20, b = 10