Challenge: Swap the Values Without Using an Extra Variable
Exchange the values of two variables without using an extra variable. We will still write pseudocode and draw a flowchart of the solution.
Problem statement
You have two variables n1 and n2 containing two numbers, and you want to swap the values that they hold, without using a third temporary variable.
Input
You take the numbers n1 and n2 as the input.
Output
The output is two variables with their values swapped.
Access this course and 1400+ top-rated courses and projects.