Swap Numbers Using Temporary Variable
Output
Enter first number: 1.20 Enter second number: 2.45 After swapping, first number = 2.45 After swapping, second number = 1.20
In the above program, the temp variable is assigned the value of the first variable.
Then, the value of the first variable is assigned to the second variable.
Finally, the temp (which holds the initial value of first) is assigned to second. This completes the swapping process.
Swap Numbers Without Using Temporary Variables
Output
Enter a: 10.25 Enter b: -12.5 After swapping, a = -12.50 After swapping, b = 10.25