Re: How to find the greatest of two numbers without using the comparison operators?
- From: "William M. Klein" <wmklein@xxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 16:34:04 GMT
Pete,
Usually I am "amused" by DD's "do your own homework" and don't follow up on
it. However, when I first saw this question last night, it had ME stumped.
Certainly, it HAD TO BE homework (because I can't think of any "good" reason to
make this restriction in a business environment). Also, when I was thinking
about it, I was NOT looking at the original question, so I didn't remember that
the two fields were numeric. Therefore, I could think of ways to do it with
words (not symbols) and without an IF (using intrinsic function MAX), or with
only = (not > or <); but I couldn't come up with a solution that actually met
the requirement. I am glad you gave the hint and others more on the solution.
P.S. To OP who gave
IF A-B ....
This may just be a typo (or my misreading a post),but Standard COBOL requires
spaces around the subtraction sign.
"A-B" is a single data item name, like ADDRESS-OF-HOUSE
while
"A - B" is an arithmetic expression
--
Bill Klein
wmklein <at> ix.netcom.com
"Pete Dashwood" <dashwood@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5jq8r6Fqh1sU1@xxxxxxxxxxxxxxxxxxxxx
"Aparajita" <aparajita.mohanty@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 comparisonNo there isn't.
operators like '<', '>','=' etc.
Is there any other operator in COBOL by which we can compare two
numbers.
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."
.
- Follow-Ups:
- References:
- Prev by Date: Re: How to find the greatest of two numbers without using thecomparison operators?
- Next by Date: Re: OT: Baby Update (final)
- 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
|