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:
Bill Cadier <[log in to unmask]>
Reply To:
Bill Cadier <[log in to unmask]>
Date:
Sat, 22 Mar 2003 14:22:33 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (50 lines)
Keven writes:

> Here is a couple of C problems that came from the unixwiz list
> I have my answers that I will post later.
> Just curious for other's solutions.
>
> Keven Miller
> [log in to unmask]
>
> To: <[log in to unmask]>
> Sent: Saturday, March 22, 2003 03:49
> Subject: [UNIX-WIZ] "Hello World" program in 'C'
>
>
> > Dear All,
> >
> > Can somebody give me solution of following
> >
> > 1. Write a "Hello World" program in 'C' without using a semicolon.
> > 2. 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 to question 2 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 :-)

Question 1 has me stumped at the moment of course question 2 may also
have me stumped and I just don't know it yet.

Bill

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

ATOM RSS1 RSS2