Program to swap two numbers

This program is to swap/exchange two numbers by using a variable.

For example:

Algorithm

  • STEP 1: START
  • STEP 2: DEFINE x, y, t
  • STEP 3: ENTER x, y
  • STEP 4: PRINT x, y
  • STEP 5: t = x
  • STEP 6: x= y
  • STEP 7: y= t
  • STEP 8: PRINT x, y
  • STEP 9: END

Java Program

Output:

Enter the value of X and Y
2
3
before swapping numbers: 2   3
After swapping: 3   2

C Program

Output:

Enter the value of X and Y
29
39
before swapping numbers: 29   39
After swapping: 39  29

Python Program

Output:

Enter the value of X?  87
Enter the value of Y?  43
before swapping numbers: 87  43
After swapping: 43  87

PHP Program

Output:

Enter the value of x
33
Enter the value of Y
22
before swapping numbers: 33  22
After swapping  22  33

C# Program

Output:

Enter the value of x and y
65
54
before swapping numbers:  65  54
After swapping:  54  65
Next Topic#




Latest Courses