39.5k views
1 vote
Variables i and j each have associated values. Swap them, so that i becomes associated with j's original value, and j becomes associated with is original value. You can use two more variables itemp and jtemp.

User Idania
by
6.3k points

1 Answer

6 votes

Answer:

The solution code is written in Python:

  1. i = 2
  2. j = 3
  3. itemp = i
  4. jtemp = j
  5. i = jtemp
  6. j = itemp

Step-by-step explanation:

Given the i and j hold their respective values (e.g. 2 and 3) (Line 1-2). We can create another two more variables itemp and jtemp to hold the values of i and j (Line 3- 4). Next, we assign jtemp to i and itemp to j. This will enable the previous value of j assigned to i and previous value of i assigned to j (Line 5-6).

User Cosmin Cosmin
by
5.7k points