1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

find smallest of three numbers without using comparsion operator

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

  1. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    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. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    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. alok

    alok New Member

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

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    No Alok its not comparison operator but its an inference that a>b or a<b.
     
  5. alok

    alok New Member

    Joined:
    Jul 24, 2004
    Messages:
    127
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    S/W Engg
    Home Page:
    May be
    really i can't understand
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    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. alok

    alok New Member

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

    elec.shabnam New Member

    Joined:
    Feb 13, 2008
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    sir what is msb
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Most significant bit
     
  10. rlearntowin1

    rlearntowin1 New Member

    Joined:
    Feb 26, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    i also needed this
     

Share This Page