Frage im Vorstellungsgespräch bei Maruti Suzuki

Swap two numbers without using third variable

Antwort im Vorstellungsgespräch

Anonym

11. Sept. 2024

// Let the two numbers be a and b a = a + b; // Step 1: Add both numbers b = a - b; // Step 2: Subtract b from the sum to get a a = a - b; // Step 3: Subtract the new b from the sum to get b