Computer Science, asked by pcu7t5lasweeth, 1 year ago

Write a program to swap two numbers

Answers

Answered by WrathRaiser
0
in c/c++:
a = a+b-(b=a);

in any language(including java):
a = a^b;
b=a^b;
a=a^b;

using extra variable:
tmp=a;
a=b;
b=tmp;
Answered by AskewTronics
0

Python program and the output for the above question is listed below:

Output:

If the user input as 4 and 5, then the output is 5 and 4.

If the user input as 6 and 7, then the output is 7 and 6.

Explanation:

first_number =int(input("Enter the first number for swapping: "))#Take the first number.

Second_number =int(input("Enter the Second number for swapping: "))#Take the second number.

#Swap the number.

Third_number=first_number

first_number=Second_number

Second_number=Third_number

print("The first number and the second number after swapping is:",first_number,"and ",Second_number)#Print the number after swapping.

Code Explanation :

  • The above code is in python language, in which the first and the second line is used to instruct the user and take the input from the user.
  • Then the three expressions are used to swap the number with the help of the third variable.
  • Then the number is printed after swapping with the help of print function.

Learn More :

  • Python : https://brainly.in/question/14689905
Similar questions