'Is there any logic to solve this? [closed]

Someone ask me a very strange question which looks logically possible but I am newbie so I am asking here..

if input value is 5 return 7 and if input value is 7 return 5

the condition is you cannot use if else statement nor switch case and nor loop

how can I solve this? thanks



Solution 1:[1]

Among many other solutions, you could use

( 5 + 7 ) - i     // 12 - i

There's also

i ^ 5 ^ 7         // i ^ 2

Something clearer:

i == 5 ? 7 : 5    // Warning: Uses branching

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1