How to find the greatest of two numbers without using the comparison operators? - Programming Languages

This is a discussion on How to find the greatest of two numbers without using the comparison operators? - Programming Languages ; Frank Swarbrick wrote:[color=blue][color=green][color=darkred] >>>> On 8/31/2007 at 12:41 AM, in message[/color][/color] > <1188542463.524263.317700@i38g2000prf.googlegroups.com>, > Aparajita<aparajita.mohanty> wrote:[color=green] >> Hi, >> >> I want to find the greatest of two given numbers say 'A' and 'B. >> The condition is that I ...

+ Reply to Thread
Page 3 of 19 FirstFirst 1 2 3 4 5 13 ... LastLast
Results 21 to 30 of 184

How to find the greatest of two numbers without using the comparison operators?

  1. Default Re: How to find the greatest of two numbers without using the comparisonoperators?

    Frank Swarbrick wrote:[color=blue][color=green][color=darkred]
    >>>> On 8/31/2007 at 12:41 AM, in message[/color][/color]
    > <1188542463.524263.317700@i38g2000prf.googlegroups.com>,
    > Aparajita<aparajita.mohanty> wrote:[color=green]
    >> Hi,
    >>
    >> I want to find the greatest of two given numbers say 'A' and 'B.
    >> The condition is that I should use the IF clause but not comparison
    >> operators like '<', '>','=' etc.
    >> Is there any other operator in COBOL by which we can compare two
    >> numbers.[/color]
    >
    > Not sure why you need this, but perhaps FUNCTION MAX could give you what you
    > want?
    >
    > COMPUTE MAX = FUNCTION MAX(A B)
    >
    > Well, I guess there's no IF in that.[/color]

    You're still going to have to use an IF to tell if MAX became A or B -
    and, this still suffers from the inability to solve the question "what
    if they're equal".

    As to why, it smells quite like an educational exercise to teach the
    student that there's more than one way to do things.

    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~ / \/ _ o ~ Live from Albuquerque, NM! ~
    ~ _ /\ | ~ ~
    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    ~ Business E-mail ~ daniel @ "Business Website" below ~
    ~ Business Website ~ [url]http://www.djs-consulting.com[/url] ~
    ~ Tech Blog ~ [url]http://www.djs-consulting.com/linux/blog[/url] ~
    ~ Personal E-mail ~ "Personal Blog" as e-mail address ~
    ~ Personal Blog ~ [url]http://daniel.summershome.org[/url] ~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ !O M--
    V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e h---- r+++ z++++

    "Who is more irrational? A man who believes in a God he doesn't see,
    or a man who's offended by a God he doesn't believe in?" - Brad Stine

  2. Default Re: How to find the greatest of two numbers without using thecomparison operators?


    "Pete Dashwood" <dashwood@removethis.enternet.co.nz> wrote in message
    news:5jro26F117mpU1@mid.individual.net...[color=blue]
    >
    >
    > "Rick Smith" <ricksmith@mfi.net> wrote in message
    > news:13dggs41m0sc4c@corp.supernews.com...[/color]
    [snip][color=blue][color=green]
    > > Another intereting approach might be:
    > > -----
    > > evaluate
    > > function ord-max(A B) - function ord-min(A B)
    > > when 1
    > > display "A is less than B"
    > > when 0
    > > display "A is equal to B"
    > > when -1
    > > display "A is greater than B"
    > > end-evaluate
    > > -----
    > >
    > > A and B may be either numeric or alphanumeric, as long as
    > > they are the same.
    > >[/color]
    > A nice solution Rick. Good job.
    >
    > (At least you thought about it ... :-))[/color]

    I was just using some erudition triggered by the mention
    of intrinsic functions. <g>




  3. Default Re: How to find the greatest of two numbers without usingthecomparison operators?



    "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message
    news:46D84B1D.6F0F.0085.0@efirstbank.com...[color=blue][color=green][color=darkred]
    >>>> On 8/31/2007 at 10:32 AM, in message[/color][/color]
    > <13dggs41m0sc4c@corp.supernews.com>,
    > Rick Smith<ricksmith@mfi.net> wrote:
    >[color=green]
    >> "Frank Swarbrick" <Frank.Swarbrick@efirstbank.com> wrote in message
    >> news:46D7E17F.6F0F.0085.0@efirstbank.com...
    >> [snip][color=darkred]
    >>> Not sure why you need this, but perhaps FUNCTION MAX could give you what[/color]
    >> you[color=darkred]
    >>> want?
    >>>
    >>> COMPUTE MAX = FUNCTION MAX(A B)[/color]
    >>
    >> Another intereting approach might be:
    >> -----
    >> evaluate
    >> function ord-max(A B) - function ord-min(A B)
    >> when 1
    >> display "A is less than B"
    >> when 0
    >> display "A is equal to B"
    >> when -1
    >> display "A is greater than B"
    >> end-evaluate
    >> -----
    >>
    >> A and B may be either numeric or alphanumeric, as long as
    >> they are the same.[/color]
    >
    > This whole discussion makes me wonder if the OP is trying to win an
    > "Obfuscated Cobol" contest!
    >
    > :-)
    >[/color]
    Frank, it is hardly fair to blame the OP for triggering the subsequent
    outpourings from the denizens of CLC :-) He asked a simple question; what
    happened after that is what makes this Newsgroup great...:-)

    Pete.
    --
    "I used to write COBOL...now I can do anything."



  4. Default Re: How to find the greatest of two numbers without using the comparison operators?

    In article <5jrnpsF10st0U1@mid.individual.net>,
    Pete Dashwood <dashwood@removethis.enternet.co.nz> wrote:

    [snip]
    [color=blue]
    >Sadly, as is often the case today, the OP simply picked up a solution from
    >someone who was happy to provide it, without really bothering to think about
    >it.
    >
    >It seems to me that thinking is no longer "fashionable" and solutions via
    >the line of least resistance are more the order of the day.[/color]

    Ahhhhhh, for the Oldene Dayse, when a thinker could think things such as
    *ten* thinkers cannot, today!

    In my experience, Mr Dashwood - and it has already been acknowledged that
    our experiences are, at times, rather different - then, as now, there were
    folks who would take the 'easy way' and others who agreed with Socrates
    that 'xalapa ta kala' (difficult/harsh/not easy (are) the
    good/beautiful/noble (things)'.

    [snip]
    [color=blue]
    >Around four thousand years ago, before the distractions and pressures of
    >modern life, TV, movies, travel, entertainment... people used to think.[/color]

    They also used to die a bit earlier.
    [color=blue]
    >(Human brains are quite well adapted for this...) They worked out the
    >distance from the Earth to the Sun just by sticking sticks in the sand on a
    >beach and observing the shadows. This calculation was correct to within 5%.[/color]

    Eh? I believe you are referring to Eratosthenes calculation of the
    earth's circumference... and that was closer to 2,500 years ago, not four
    millennia.

    DD


  5. Default Re: How to find the greatest of two numbers without using the comparison operators?



    <docdwarf@panix.com> wrote in message news:fbae5i$rnu$1@reader1.panix.com...[color=blue]
    > In article <5jrnpsF10st0U1@mid.individual.net>,
    > Pete Dashwood <dashwood@removethis.enternet.co.nz> wrote:
    >
    > [snip]
    >[color=green]
    >>Sadly, as is often the case today, the OP simply picked up a solution from
    >>someone who was happy to provide it, without really bothering to think
    >>about
    >>it.
    >>
    >>It seems to me that thinking is no longer "fashionable" and solutions via
    >>the line of least resistance are more the order of the day.[/color]
    >
    > Ahhhhhh, for the Oldene Dayse, when a thinker could think things such as
    > *ten* thinkers cannot, today!
    >
    > In my experience, Mr Dashwood - and it has already been acknowledged that
    > our experiences are, at times, rather different - then, as now, there were
    > folks who would take the 'easy way' and others who agreed with Socrates
    > that 'xalapa ta kala' (difficult/harsh/not easy (are) the
    > good/beautiful/noble (things)'.
    >
    > [snip]
    >[color=green]
    >>Around four thousand years ago, before the distractions and pressures of
    >>modern life, TV, movies, travel, entertainment... people used to think.[/color]
    >
    > They also used to die a bit earlier.
    >[color=green]
    >>(Human brains are quite well adapted for this...) They worked out the
    >>distance from the Earth to the Sun just by sticking sticks in the sand on
    >>a
    >>beach and observing the shadows. This calculation was correct to within
    >>5%.[/color]
    >
    > Eh? I believe you are referring to Eratosthenes calculation of the
    > earth's circumference... and that was closer to 2,500 years ago, not four
    > millennia.[/color]

    Nope. I was not referring to Eratosthenes at all. Had I been, I would have
    said so.

    Not that it matters, but I was referring to the same people who, 5000 years
    ago gave us the current 365 day calendar (based on their astronomical
    observations), built instruments to measure time and angles around 4500
    years ago, documented over 40 constellations which could be used for
    navigation 3300 years ago, had many of their accomplishments claimed by
    Greeks, (who they influenced immensely...Aristole acknowledged their
    superior Astronomical achievements and Pythagoras was tutored by them), and
    passed down across thousands of years, through their closed Priesthood,
    knowledge that was lost, destroyed (Clement of Alexandria documented at
    least four of their books on Astronomy that were in the famous library), and
    then re-discovered centuries later.

    No more clues... do your own homework. :-)

    Pete.
    --
    "I used to write COBOL...now I can do anything."



  6. Default [OT] Re: How to find the greatest of two numbers without using the comparison operators?

    May I repeat what I previously stated -
    If you have something to say that is not
    anything to do with the original topic, then
    please OT it.
    Bill has already said this.
    This is no longer funny.
    Especially for people that are trying this
    list for an answer to their problems/questions.

    Roger



  7. Default Re: [OT] Re: How to find the greatest of two numbers without using the comparison operators?

    "Roger While" <simrw@sim-basis.de> wrote in message
    news:fbbc0b$o1a$02$1@news.t-online.com...[color=blue]
    > May I repeat what I previously stated -
    > If you have something to say that is not
    > anything to do with the original topic, then
    > please OT it.
    > Bill has already said this.
    > This is no longer funny.
    > Especially for people that are trying this
    > list for an answer to their problems/questions.[/color]

    If this specific thread/ this specific question is a source for answers, the
    "off-topic" comments are far more important than the answer.

    MCM





  8. Default Re: How to find the greatest of two numbers without using the comparison operators?

    "Pete Dashwood" <dashwood@removethis.enternet.co.nz> wrote in message
    news:5jrnpsF10st0U1@mid.individual.net...[color=blue]
    > Sadly, as is often the case today, the OP simply picked up a solution from
    > someone who was happy to provide it, without really bothering to think
    > about it.
    >
    > It seems to me that thinking is no longer "fashionable" and solutions via
    > the line of least resistance are more the order of the day....[/color]

    This is a really good point.

    If you look at the classified ads, you'll see what employers want in
    addition to 'technical competence' are three 'intangibles':

    First, they all want "communications skills" - however you want to define
    that.

    Second, they all want a "team player" - whatever that means.

    And, they want "problem solving skills" - another somewhat amorphous term.

    While in this case the OP demonstrated communications skills and "team play"
    (he *was* able to express his challenge (?) and had no problems accepting
    the suggestions of others), his 'problem solving skills' were left
    unenhanced.

    I have a saying I use when asked the difference between school and Real
    Life: "In Real Life, the answers are *not* found in Appendix B."

    But a young man I encountered some years ago had his own take on this: "In
    Real Life, *all* problems are 'story' problems."

    I think this thread demonstrates how that young man's view would be
    something for the OP to keep in mind.

    MCM












  9. Default Re: [OT] Re: How to find the greatest of two numbers without using the comparison operators?



    "Roger While" <simrw@sim-basis.de> wrote in message
    news:fbbc0b$o1a$02$1@news.t-online.com...[color=blue]
    > May I repeat what I previously stated -
    > If you have something to say that is not
    > anything to do with the original topic, then
    > please OT it.[/color]

    Most of the time I do. Not always...
    [color=blue]
    > Bill has already said this.[/color]

    It has been said here on a number of occasions by a number of people. Most
    of us do try and adhere to it, but we don't always succeed. You getting
    strident about it is unlikely to make a difference, and may very well
    alienate the people you are hoping to persuade.
    [color=blue]
    > This is no longer funny.[/color]

    Well, Gee, I'm sorry you're losing your sense of humour

    As it is an umoderated forum there is nothing you can do about it.

    I suggest you accept it for what it is; an unmoderated Usenet forum and not
    your personal Helpline.

    If you post here, there is a risk that your questions will be taken off
    topic, ignored completely, or answered brilliantly. It is worth what you pay
    for it.
    [color=blue]
    > Especially for people that are trying this
    > list for an answer to their problems/questions.
    >[/color]

    Many people access this list for a myriad of reasons. Why is your reason
    more important than anybody else's?

    As for getting help on questions, I have answered a number of them here
    recently. They ranged from sending faxes with COBOL ,to suggesting how
    comparisons might be made without using comparison operators (which IS the
    topic of this thread).

    Actually Roger, I DO prefix topics that are OT with an OT prefix, if I
    originate the topic. In this case I didn't orginate the topic and it is
    debatable how far off it I wandered. As there are no thought police here to
    enforce on-topic postings, and as most of us do adhere to a code of conduct
    that is NOT enforced, I suggest you are way out of order with this post.

    I'm not sure what I would do if I were you. But I wouldn't be getting
    unwrapped about it.

    Calm down and accept CLC for what it is. No one is setting out to
    deliberately irritate you.

    Pete.
    --
    "I used to write COBOL...now I can do anything."



  10. Default Re: [OT] Re: How to find the greatest of two numbers without using the comparison operators?

    "Michael Mattias" <mmattias@talsystems.com> wrote in message
    news:%hdCi.4606$JD.1291@newssvr21.news.prodigy.net...[color=blue]
    > "Roger While" <simrw@sim-basis.de> wrote in message
    > news:fbbc0b$o1a$02$1@news.t-online.com...[color=green]
    >> May I repeat what I previously stated -
    >> If you have something to say that is not
    >> anything to do with the original topic, then
    >> please OT it.
    >> Bill has already said this.
    >> This is no longer funny.
    >> Especially for people that are trying this
    >> list for an answer to their problems/questions.[/color]
    >
    > If this specific thread/ this specific question is a source for answers,
    > the "off-topic" comments are far more important than the answer.
    >[/color]
    I agree :-) (but then, I would say that... :-))

    Thanks for pointing it out, Michael.

    Pete.
    --
    "I used to write COBOL...now I can do anything."



+ Reply to Thread
Page 3 of 19 FirstFirst 1 2 3 4 5 13 ... LastLast

Similar Threads

  1. greatest of two numbers
    By Application Development in forum C
    Replies: 37
    Last Post: 12-29-2007, 06:29 PM
  2. Combinations of numbers/operators?
    By Application Development in forum RUBY
    Replies: 6
    Last Post: 08-25-2007, 03:35 PM
  3. automatic type conversion for comparison operators
    By Application Development in forum Python
    Replies: 3
    Last Post: 07-26-2007, 11:13 PM
  4. type conversions for comparison operators
    By Application Development in forum Python
    Replies: 1
    Last Post: 07-18-2007, 09:38 PM
  5. Style or speed with comparison operators sequences?
    By Application Development in forum c++
    Replies: 10
    Last Post: 02-21-2007, 05:16 AM