HP3000-L Archives

March 2003, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"F. Alfredo Rego" <[log in to unmask]>
Reply To:
F. Alfredo Rego
Date:
Sat, 22 Mar 2003 15:32:04 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (46 lines)
At 2:22 PM -0700 3/22/03, Bill Cadier wrote:

>  > Write a 'C' program without using any loop (if, for, while etc) to
>  > print numbers from 1 to 100 and 100 to 1;
>
>Here's an answer ... that I don't think breaks any of the rules
>
>int dispnum ( int num, int last )
>{
>printf("%d\n", num);
>return((num > last) ?
>     (num=(num < 100) ? dispnum(++num, ++last) : dispnum(num, num)) :
>     (num=(num > 1) ? dispnum (--num, --last) : 0 ));
>}
>
>void main()
>{
>dispnum(1, 0);
>}
>
>How's that? A little recursion but no (explicit) if's in there.
>Notice also the judicious absence of comments :-)

Very nice!  It runs beautifully on my Gypsy hp3000 and, of course, on
my Mac PowerBook (which I use as MPE's front end), under both Mac OS 9
and Mac OS X.  Just for kicks, I also ran it on Windows XP Professional
(under Virtual PC).

Do you play chess?  I'll bet you checkmate your opponents in a couple
of moves!

   _______________
  |               |
  |               |
  |            r  |  Alfredo                     [log in to unmask]
  |          e    |                           http://www.adager.com
  |        g      |  F. Alfredo Rego
  |      a        |  Manager, R & D Labs
  |    d          |  Adager Corporation
  |  A            |  Sun Valley, Idaho 83353-3000            U.S.A.
  |               |
  |_______________|

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2