find smallest of three numbers without using comparsion operator

go4expert's Avatar, Join Date: Aug 2004
Team Leader
Hello Friends.

I am not able to solve a question in C If u have any idea pls help me

The Question is

program to find smallest of three numbers without using comparsion operator

Thanks
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Hello

do something like this
a,b,c
d = a-b;
get MSB of d
if(MSB)
no is +ve and a>b and so compare a and c
else
no is -ve and a<b so compare b and c in similar fashion.

Thanks
Shabbir Bhimani
alok's Avatar
Ambitious contributor
Quote:
Originally Posted by shabbir
Hello

do something like this
a,b,c
d = a-b;
get MSB of d
if(MSB)
no is +ve and a>b and so compare a and c ------------------------->1
else
no is -ve and a<b so compare b and c in similar fashion.------------------------>2

Thanks
Shabbir Bhimani
But , shabbir you are still using the Comparison operator in 1 & 2
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
No Alok its not comparison operator but its an inference that a>b or a<b.
alok's Avatar
Ambitious contributor
May be
really i can't understand
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Code:
a,b,c
d = a-b;
get MSB of d
if(MSB)
  no is +ve and a>b and so compare a and c
  //Number d is positive and so we get a as greater than b 
  //Now compare a and c in similar fashion
else
  no is -ve and a<b so compare b and c in similar fashion.
  //Number d is negative and so we get a as less than b 
  //Now compare b and c in similar fashion
I hope this comments as explanation helps you to understand.

Thanks
Shabbir Bhimani
alok's Avatar
Ambitious contributor
Thanks shabbir
for taking out some time from you busy schedule to help me understand
thanks again
elec.shabnam's Avatar, Join Date: Feb 2008
Ambitious contributor
Quote:
Originally Posted by alok
But , shabbir you are still using the Comparison operator in 1 & 2
sir what is msb
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by elec.shabnam
sir what is msb
Most significant bit
rlearntowin1's Avatar, Join Date: Feb 2008
Go4Expert Member
i also needed this