KnowledgeBoat Logo

Computer Science

Write a program to read three numbers in three variables and swap first two variables with the sums of first and second, second and third numbers respectively.

Python

Python Funda

198 Likes

Answer

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
print("The three number are", a, b, c)
a, b = a + b, b + c
print("Numbers after swapping are", a, b, c)

Output

Enter first number: 10
Enter second number: 15
Enter third number: 20
The three number are 10 15 20
Numbers after swapping are 25 35 20

Answered By

125 Likes


Related Questions