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
Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari View all posts by Editorial Staff