Introduction
  • In this article, I'm explaining how to swap two numbers in C.
Software Requirements
  • Turbo C++ OR C
Programming
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int x, y, temp;
  5. printf("Enter the value of x and y\n");
  6. scanf("%d%d", &x, &y);
  7. printf("Before Swapping\nx = %d\ny = %d\n",x,y);
  8. temp = x;
  9. x = y;
  10. y = temp;
  11. printf("After Swapping\nx = %d\ny = %d\n",x,y);
  12. return 0;
  13. }
Explanation
  • 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.

    srk
Output

Output