A Program to Swap Dynamic Value Without 3rd Variable
In this example, we are giving a program to swap dynamic value without using the 3rd variable.
Program to to swap dynamic value without the 3rd variable:
#include <stdio.h>
#include <conio.h>
int main() {
printf("Enter the 1st value: ");
scanf("%d", &a);
printf("Enter the 2nd value: ");
scanf("%d", &b);
// code to swap 'a' and 'b'
a = a + b;
b = a - b;
a = a - b;
printf("After swapping: a = %d, b = %d", a, b);
return 0;
}
Output:
Enter the 1st value: 10 Enter the 2nd value: 20 After swapping: a = 20, b = 10