int cond (int x, int y, int z) { return (x==0)*z + (x!=0)*y; }
On Jul 21, 10:29 pm, BALARUKESH <sbalarukesh1...@gmail.com> wrote: > Ternary operator- x? y : z > Implement it in a function: int cond(int x, int y, int z); using only > ~, !, ^, &, +, |, <<, >> no if statements, or loops or anything else, > just those operators, and the function should correctly return y or z > based on the value of x. You may use constants, but only 8 bit > constants. You can cast all you want. You're not supposed to use extra > variables, but in the end, it won't really matter, using vars just > makes things cleaner. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.