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 15:47:06 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (57 lines)
> 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]
>

< snip >

Ok, I think I have an answer for question 1...

> > 1. Write a "Hello World" program in 'C' without using a semicolon.

Let's say I just happened to have an include file that defined a macro
like this

#define say(what) printf(#what "\n");

Then I write the hello world program as

#include "say.h"
void main()
{ say(Hello World!) }

Kind of cheating since the macro has a semicolon in it but the program source
itself doesn't.

> > 2. Write a 'C' program without using any loop (if, for, while etc) to
> print
> > numbers from 1 to 100 and 100 to 1;

BTW, my first attempt wasn't quite geeky enough, this is actually better
(in terms of being even less readable :-)

int dispnum ( int num )
{
printf("%d\n", (num>0) ? num : -num);
return((num > 0) ?
    (num=(num < 100) ? dispnum(++num) : dispnum(-num)) :
    (num=(num < -1 ) ? dispnum (++num) : 0 ));
}

void main()
{
dispnum(1);
}

Well... it's a nice day here in Albuquerque so I'm going to go enjoy it now
that I can't remember why I logged on in the first place. It might have had
something to do with "work" I need to catch up on but this was more fun.

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