Computer Science Of Engineering

Simple and practical computer science tutorials, programming guides, and engineering concepts for students and beginners.

Breaking

Tuesday, April 22, 2025

Write a python program to swap two numbers without using a temporary variable.

 # Input two numbers from user

a = int(input("Enter first number (a): "))

b = int(input("Enter second number (b): "))


print(f"Before swapping: a = {a}, b = {b}")


# Swapping without using a temporary variable

a = a + b

b = a - b

a = a - b


print(f"After swapping: a = {a}, b = {b}")



Output:


No comments:

Post a Comment