# find smallest of three numbers without using comparsion operator

Discussion in 'C' started by go4expert, Aug 10, 2004.

1. ### go4expertModerator

Joined:
Aug 3, 2004
Messages:
306
7
Trophy Points:
0
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

2. ### shabbirAdministratorStaff Member

Joined:
Jul 12, 2004
Messages:
15,285
364
Trophy Points:
83
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

3. ### alokNew Member

Joined:
Jul 24, 2004
Messages:
127
2
Trophy Points:
0
Occupation:
S/W Engg
But , shabbir you are still using the Comparison operator in 1 & 2

4. ### shabbirAdministratorStaff Member

Joined:
Jul 12, 2004
Messages:
15,285
364
Trophy Points:
83
No Alok its not comparison operator but its an inference that a>b or a<b.

5. ### alokNew Member

Joined:
Jul 24, 2004
Messages:
127
2
Trophy Points:
0
Occupation:
S/W Engg
May be
really i can't understand

6. ### shabbirAdministratorStaff Member

Joined:
Jul 12, 2004
Messages:
15,285
364
Trophy Points:
83
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

7. ### alokNew Member

Joined:
Jul 24, 2004
Messages:
127
2
Trophy Points:
0
Occupation:
S/W Engg
Thanks shabbir
for taking out some time from you busy schedule to help me understand
thanks again

8. ### elec.shabnamNew Member

Joined:
Feb 13, 2008
Messages:
102
0
Trophy Points:
0
sir what is msb

9. ### shabbirAdministratorStaff Member

Joined:
Jul 12, 2004
Messages:
15,285
364
Trophy Points:
83
Most significant bit

Joined:
Feb 26, 2008
Messages:
10