Swap Two Numbers Without Third Variable
In this program, You will get the program code of Swap Two Numbers Without using Third Variable in c programming. This program can be done by using another method swap two numbers with using third variable in c.
Explanation: Swap without Third Variable
Program Code of Swap Two Numbers Without Using Third Variable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> int main() { int x, y, temp; printf("\nEnter the value of x and yn"); scanf("%d%d", &x, &y); printf("\nBefore Swapping\nx = %d\ny = %d\n", x, y); // swapping x = x+y; // x=15 y = x-y; //y=5 x = x-y; //x=10 printf("\nAfter Swapping\nx = %d\ny = %d\n", x, y); return 0; } |
Output
Check out our other C programming Examples