In some game, cards are used with numbers from 1 to N. At the entrance to the program, the number N is first given, not exceeding
In some game, cards are used with numbers from 1 to N. At the entrance to the program, the number N is first given, not exceeding 1000, and then N-1 number – the numbers of the cards (in random order). The program should display the number of the remaining card or report that the input is wrong (if the program was able to understand it), the word ERROR. Do not use tools that were not considered in the task (for example, arrays). With the given restrictions, not all input errors can be caught, but there will be no such tests.
The first Pascal variant: var n, i, x: Longint; begin Write (‘Enter n:’); Read (n); Write (‘Enter numbers:’); for i: = 1 to n-1 do begin Read (x); n: = n xor x; end; if n <> 0 then WriteLn (n) else WriteLn (‘Invalid input’); end. Second option: var n, i, x: Longint; begin Write (‘Enter n:’); Read (n); Write (‘Enter the missing number:’); ReadLn (x); for i: = 1 to n do if i <> x then n: = n xor i; if n <> 0 then WriteLn (n) else WriteLn (‘Invalid input’); end. Third option: var n, s, i, x: longint; begin read (n); s: = n; for i: = 1 to n – 1 do begin read (x); s: = s xor x xor i; end; writeln (s); end.