Introduction
- In this article, I'm explaining how to swap two numbers in C.
Software Requirements
- Turbo C++ OR C
Programming
- #include <stdio.h>
- int main()
- {
- int x, y, temp;
- printf("Enter the value of x and y\n");
- scanf("%d%d", &x, &y);
- printf("Before Swapping\nx = %d\ny = %d\n",x,y);
- temp = x;
- x = y;
- y = temp;
- printf("After Swapping\nx = %d\ny = %d\n",x,y);
- return 0;
- }
- In the above program, before we swap the numbers, the values of x and y are in the correct order, as we have assigned them. After swapping, the numbers are interchanged.

Output



Sr KarthigaPosted Jul 8, 2016, 1:14 AM
Clear explanation
Sr KarthigaPosted Jul 8, 2016, 1:13 AM
Nice one