The instructions: x = x + y y = x - y x = x - y result in:
2015
The instructions: x = x + y y = x - y x = x - y result in:
- A.
Retain the values of x and y
- B.
Complement the value of x and y
- C.
Swap x and y
- D.
Negates x and y
- E.
Question not attempted
Attempted by 1104 students.
Show answer & explanation
Correct answer: C
Step 1: Start with initial values of x and y.
Step 2: After x = x + y, x becomes the sum of the original values of x and y.
Step 3: After y = x - y, y becomes the original value of x (since x is now x + y, and subtracting y gives back the original x).
Step 4: After x = x - y, x becomes the original value of y (since x is now x + y, and subtracting the new y (which is original x) gives back the original y).
Thus, the values of x and y are swapped.
हिन्दी उत्तर:
चर x और y के शुरुआती मानों से शुरू करें।
x = x + y के बाद, x मूल x और y का योग बन जाता है।
y = x - y के बाद, y मूल x का मान बन जाता है (क्योंकि x अब x + y है, और y घटाने पर मूल x मिलता है)।
x = x - y के बाद, x मूल y का मान बन जाता है (क्योंकि x अब x + y है, और नए y (जो मूल x है) को घटाने पर मूल y मिलता है)।
इस प्रकार, x और y के मान आपस में बदल जाते हैं।