Re: How to find the greatest of two numbers without using the comparison operators?
- From: Aparajita <aparajita.mohanty@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 12:03:19 -0000
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.
Thanks!
Aparajita
.
- Follow-Ups:
- Re: How to find the greatest of two numbers without using the comparison operators?
- From: Pete Dashwood
- Re: How to find the greatest of two numbers without using the comparison operators?
- From: Michael Mattias
- Re: How to find the greatest of two numbers without using the comparison operators?
- References:
- Prev by Date: Re: OT: Baby Update (final)
- Next by Date: Re: How to find the greatest of two numbers without using the comparison operators?
- Previous by thread: Re: How to find the greatest of two numbers without using the comparison operators?
- Next by thread: Re: How to find the greatest of two numbers without using the comparison operators?
- Index(es):
Relevant Pages
|