Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   find smallest of three numbers without using comparsion operator (http://www.go4expert.com/forums/smallest-using-comparsion-operator-t110/)

go4expert 10Aug2004 15:31

find smallest of three numbers without using comparsion operator
 
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 10Aug2004 15:33

Re: find smallest of three numbers without using comparsion operator
 
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 11Aug2004 12:27

Re: find smallest of three numbers without using comparsion operator
 
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 11Aug2004 12:46

Re: find smallest of three numbers without using comparsion operator
 
No Alok its not comparison operator but its an inference that a>b or a<b.

alok 24Aug2004 19:55

Re: find smallest of three numbers without using comparsion operator
 
May be
really i can't understand

shabbir 24Aug2004 21:53

Re: find smallest of three numbers without using comparsion operator
 
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 25Aug2004 13:05

Re: find smallest of three numbers without using comparsion operator
 
Thanks shabbir
for taking out some time from you busy schedule to help me understand
thanks again

elec.shabnam 26Feb2008 17:01

Re: find smallest of three numbers without using comparsion operator
 
Quote:

Originally Posted by alok
But , shabbir you are still using the Comparison operator in 1 & 2

sir what is msb

shabbir 26Feb2008 19:49

Re: find smallest of three numbers without using comparsion operator
 
Quote:

Originally Posted by elec.shabnam
sir what is msb

Most significant bit

rlearntowin1 27Feb2008 09:29

Re: find smallest of three numbers without using comparsion operator
 
i also needed this


All times are GMT +5.5. The time now is 20:32.