In this program, we will explain how to swap two numbers without using any third variable using c programming language.
We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.
int x = 10, y = 20;
x = x + y; // x now becomes 30
y = x - y; // y becomes 10
x = x - y; // x becomes 20
printf("After Swapping: x = %d, y = %d", x, y);
After Swapping: x = 20, y = 10
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.