
Correct : 46
The output of the program is 46.
The function gate() processes the input number 14362 digit by digit from left to right using integer division and modulo operations. It uses a variable turn that flips between 0 and 1 at every step — when turn is 1, the current digit is included in the result; when turn is 0, the digit is skipped.
Since turn starts at 0, the first digit is always skipped. Here"s how the digits of 14362 are processed:
• Digit 1 (position 0): turn = 0 → skipped
• Digit 4 (position 1): turn = 1 → included → newnum = 4
• Digit 3 (position 2): turn = 0 → skipped
• Digit 6 (position 3): turn = 1 → included → newnum = 46
• Digit 2 (position 4): turn = 0 → skipped
So the function collects digits at odd positions (1-indexed: 2nd and 4th) — which are 4 and 6 — and returns 46.
Similar Questions
Total Unique Visitors