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




"Aparajita" <aparajita.mohanty@xxxxxxxxx> wrote in message
news:1188561799.566239.84930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Aug 31, 3:28 pm, "Pete Dashwood"
<dashw...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
"Aparajita" <aparajita.moha...@xxxxxxxxx> wrote in message

news:1188542463.524263.317700@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi,

I want to find the greatest of two given numbers say 'A' and 'B.

That would be the "greater" of two numbers; the "greatest" implies at
least
three...

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.

No there isn't.

But what you want CAN be done.

a clue: Check out the COBOL SIGN test.

Then think about how a computer is able to make comparisons. How would a
"compare" instruction (on any platform) "work"? If you had to build a
computer, how would you build a "compare" instruction? Given that all you
can do is arithmetic and sign checking, how would you implement a
"compare"?

Post your thoughts here, and we'll see how you go.

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

Hi Pete,
Thanks for your response.
I got an alternate solution,
like this
IF A-B IS POSITIVE
DISPLAY "A IS GREATER"
ELSE
DISPLAY "B IS GREATER"
END-IF.

What is your opinion on the above solution? Or if you find any
limitations or constraints with this code, please let me know.

Yes, you are on the right track. But the code is flawed.

What happens if A = B? Your code will incorrectly display that "B IS
GREATER".

You should seek to understand the code yourself, then you won't need my
opinion (or anyone else's...) as to constraints or limitations on it. Had
you taken my advice and checked out the COBOL SIGN test you could have
written a better solution. HINT: It's not too late... :-)

Read about the COBOL SIGN Test, then see if you can fix it yourself.

Picking up a solution from someone else is only one way to solve a problem,
although it is sometimes a valid approach. Always analyse whatever you pick
up, until you understand it thoroughly yourself. If you don't understand it,
don't use it... :-)

Cheers,

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


.



Relevant Pages

  • Re: interesting use of NEXT SENTENCE vs. CONTINUE
    ... I am asking how a machine language BRANCH instruction (which has a SINGLE ... can be SLOWER than a machine language COMPARE instruction that has ... If 150 programmers are each compiling 5 COBOL programs ... possibility that ALTERED code in your environment may not be a good thing, ...
    (comp.lang.cobol)
  • Re: Performance of PACK/UNPACK instructions
    ... Cobol will pack before doing a compare for when the operands in the ... compare are not the same data type and atleast one operand is numeric. ... Cobol will not do a pack/unpack pair for a compare ... ... hence instructions like pack and unpack. ...
    (bit.listserv.ibm-main)
  • Re: interesting use of NEXT SENTENCE vs. CONTINUE
    ... It's my recollection that for at least early S/360 COBOL implementations the ... branch instruction to which the GO TO after the ALTERed LABEL pointed. ... compare that concerns me, it's the cost of the PCW manipulation (at the time ... > I see standards as being a helpful guide to new people joining the team. ...
    (comp.lang.cobol)
  • Re: How to find the greatest of two numbers without using the comparison operators?
    ... it HAD TO BE homework (because I can't think of any "good" reason to ... This may just be a typo,but Standard COBOL requires ... "A - B" is an arithmetic expression ... Is there any other operator in COBOL by which we can compare two ...
    (comp.lang.cobol)
  • Re: how to compare two time
    ... WC> int begin = time; ... WC> How about COBOL? ... When you want to compare times, it is better to use these functions ... FUNCTION INTEGER-OF-DATE which for many applications is more important ...
    (comp.lang.cobol)