Sunday, August 28, 2011

Write a method which finds the maximum of two numbers You should not use if-else or any other comparison operator.

sol1:
int c = (a - b) >> 31;
max = c & b | ~c & a;

sol2:
max=(a+b+abs(a-b))/2;
min=(a+b-abs(a-b))/2;

No comments:

Post a Comment