write a program to swap two number
时间: 2024-03-21 19:42:09 浏览: 76
Linux 交换空间(SWAP)配置
Sure, here's an example program in Python to swap two numbers:
```
# take two numbers as input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# print the original numbers
print("Original numbers: num1 =", num1, ", num2 =", num2)
# swap the numbers
temp = num1
num1 = num2
num2 = temp
# print the swapped numbers
print("Swapped numbers: num1 =", num1, ", num2 =", num2)
```
This program takes two numbers as input from the user, stores them in variables `num1` and `num2`, and then swaps their values using a temporary variable `temp`. Finally, it prints the original and swapped numbers for verification.
阅读全文