SOLVED:some Good questions

Let x,y,z be 3 integers . We have to find the greatest of 3 integers, without using relational and conditional operator?
ANSWER IS THERE IN COMMENTs ,still u can add ur answer .

10 comments:

sathish.kulal said...

i had this question in my google interview

Unknown said...
This comment has been removed by the author.
Unknown said...

Try this solution
step 1:int a,b,c;
step 2:a=3;b=5;c=7;
step 3:int d=(a+b+2*c+Abs(a-b)+Abs(a+b-2*c+Abs(a-b)))/4;

sathish.kulal said...

Yes ur answer is rite ,
for two variable a and b
max=(a+b+abs(a-b))/2
so we can derive three variable or more.

sathish.kulal said...

My Answer1: is in the above comment.

sathish.kulal said...

ANSWER 2:

int max (int numer1 , int number2)
{
int array[2] = { number1 ,number2 }

return ( array [ !!(number1 / number2 )]

sathish.kulal said...

Answer 3:

!!(number1-number2) && return number1
!!(number2-number1) && return number2

sathish.kulal said...

Answer 4 :

(number1-number2)& 0x1000000 && return number1

(number2-number1)& 0x1000000 && return number2

note right most bit checking method

gopu said...

The equation below will work only if x != y != z.



MaxOf(x, y ,z) = x*((y - x) & (z - x)& 0x8000)/0x8000

+ y*((x - y) & (z - y)& 0x8000)/0x8000

+ z*((x - z) & (y - z)& 0x8000)/0x8000;

gopu said...

int a,b,c; //a,b,c are the three number initially

int k,m,n;

k=a/b;

m=b/a;

n=(ka+mb)/(k+m); // here we get the biggest of two numbers



now

a=n;

b=c;

n=(ka+mb)/(k+m); //this wil give the biggest of three number a,b,c