Notification texts go here Contact Us Click here

Program to swap two numbers without using third variable

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
  1. """program to swap two numbers without using third """
  2.  
  3. = int(input("Enter the first number : "))   #user input first number
  4. = int(input("Enter the second number : "))  #user input second number
  5.  
  6. print("Before swapping:")
  7. print("a =", a)
  8. print("b =", b)
  9.  
  10. = a + b
  11. = a - b
  12. = a - b
  13.  
  14. print("After swapping:")
  15. print("a =", a)
  16. print("b =", b)
  17. print ('\U0001F603')
  18.  
  19. OUTPUT :
  20. Enter the first number : 10
  21. Enter the second number : 50
  22. Before swapping:
  23. = 10
  24. = 50
  25. After swapping:
  26. = 50
  27. = 10
  28. 😃
  29.  
  30.  
  31. Enter the first number : 100
  32. Enter the second number : 200
  33. Before swapping:
  34. = 100
  35. = 200
  36. After swapping:
  37. = 200
  38. = 100
  39. 😃
  40.  
  1. """ Progrqm to swap two numbers using third variable """
  2.  
  3.  
  4. num1= int(input("Enter the first number: "))  #input first number 
  5. num2 = int(input("Enter the second number: ")) #input second number
  6. print("Before Swapping:\nnum1 =", num1, ", num2 =", num2)
  7. temp = num1
  8. num1 = num2
  9. num2 = temp
  10. print("After Swapping:\nnum1 =", num1, ", num2 =", num2)
  11.  
  12.  
  13. print ('\U0001F603')
  14.  
  15. OUTPUT :
  16.  
  17. Enter the first number: 10
  18. Enter the second number: 50
  19. Before Swapping:
  20. num1 = 10 , num2 = 50
  21. After Swapping:
  22. num1 = 50 , num2 = 10
  23. 😃
  24.  

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.