Describe a function (in C) that does the following Input : an integer. Output: if that integer is 4, the function returns 7. if that integer is 7, the function returns 4. constraints: the input is SURE to be either 4 or 7. no need to validate. you are not allowed to use any condition/flow commands (if, switch, while, for, trinary operator...) you are not allowed to use any external library or import anything (like math..) you are not allowed to use %(modulu), * (multiplication)
Anonymous
The interviewer gave me the constrains each time i thought of a solution. so my first trivial solution was using an "if". than he said "now try without any condition" - so i came up with multiplication (return 38/num) - and than "try without multiplication as well..." and so on. ultimatly there are (i think) 2 good solutions here: 1. return 11 - num 2. return num XOR 3
Check out your Company Bowl for anonymous work chats.