Upgrade to access all content for this subject

Which of the following code segments will multiply x by 2 if it’s even, multiply x by -2 if it’s odd, and add 1 to x if it’s zero?

IF (x MOD 2 = 0) { IF (x = 0) {x ← x + 1} ELSE {x ← x * 2} } ELSE {x ← x * -2}

IF (x = 0) {x ← x + 1} IF (x MOD 2 = 1) {x ← x * -2} IF (x MOD 2 = 0) {x ← x * 2}

IF (x = 0) {x ← x + 1} IF (x MOD 2 = 0) AND (NOT (x = 0)) {x ← x * 2} IF (x MOD 2 = 1) {x ← x * -2}

IF (x = 0) {x ← x + 1} IF (x MOD 2 = 1) {x ← x * -2} ELSE {x ← x * 2}