Computer Science, asked by ayushi25553, 9 months ago

write a program to interchange the values of two variable using third variable​

Answers

Answered by Anonymous
37

\huge{\bigstar{\underline{\underline{\bf{Python\:(7.3.4)}\bigstar}}}}

\huge{\bullet{\underline{\sf{Coding:-}}}}}

#To take inputs from the user

\textsf{x = input('Enter value of x: ')}

\textsf{y = input('Enter value of y: ')}

# create a temporary variable and swap the values

temp = x

x = y

y = temp

\textsf{print('The value of x after swapping: {}'.format(x))}

\textsf{print('The value of y after swapping:{}'. format(y))}

\huge{\textsf{\# Program ends.....}}

Answered by AskewTronics
1

Below are the Q-Basic program and output for the above question:

Output :

If the user input as 5 and 4, then it will prints 4 and 5.

If the user input as 7 and 5, then it will prints 5 and 7.

Explanation:

INPUT "Enter the first number for swapping",first_number 'Take the first number from user.

INPUT "Enter the Second number for swapping",Second_number' Take the second number from user.

Third_Number=first_number'Swap the number using third variable.

first_number=Second_number

Second_number=Third_Number

PRINT "The number after Swapping is : ",first_number,"and ",Second_number'Print the number after swapping.

Code Explanation :

  • The above code is in Q-Basic language, in which the first and the second line is used to take the input from the user.
  • Then the three-line expression is using to replace the value, for this, it will transfer the second variable value on the third variable and then the first variable value on the second variable and then the third variable value is on the first variable.

Learn More :

  • Q-BASIC : https://brainly.in/question/2343849
Similar questions