In the program integer type variable declare(x,y) which contains the value. To swap the variables we need to declare them with unique values. To swap the variables without using third variable and in this case we also do not use the Temp (temporary) variable. Some operators for manipulation used for swapping the variable.
This Program is to swapping the two Variables without using Third variable.
- Entering the number.
- Using Logic to swap variables.
- Display the Output on the screen.
Syntax of Swapping:
Here is source code of the C program Swap two variables without Using third variable. The C program is successfully compiled. The program output is also shown below.
printf("\nPlease Enter a Number (x):");
printf("\nPlease Enter a Number (y):");
printf("\n\nValues Before Swapping\nx=[%d]\ny=[%d]",x,y);
printf("\n\nValues After Swapping\nx=[%d]\ny=[%d]",x,y);