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 *
|