print 1 to n without any conditional statement, loop or jump.

M

Malcolm McLean

dev_cool said:
#include<iostream.h>

class abc{
public:
static int i;
abc()
{
cout<<i++<<endl;
}
};

int abc :: i = 1;

int main() {
int n = 100;
abc *pt;

pt = new abc[n];

return 0;
}
The question is whether disguised loops and conditions count.
For instance a compound conditional

x = a && b();

will execute an if statement in disguise, because of the intelligent
guarding rule.

Similarly your friend's example, which is C++, is just executing a hidden
for() loop as C++ calls constructors on an array.
 
C

Christopher Benson-Manica

Malcolm McLean said:
The question is whether disguised loops and conditions count.

If those are unacceptable, Dave Vandervies' correction elsethread of my
version relying on recursive calls to raise() is one possible
alternative.
 
J

John Bode

I'm only posting this solution because I'd like the gurus to tell me
what's wrong with it (it seems to work):

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void handleZero( int ignore ) {

}

void handleOne( int ignore ) {
printf( "\n" );

You really, *really* don't want to call a library function from an
interrupt handler (other than signal), since library functions may
raise signals themselves, and they are not guaranteed to be
reentrant. I've fixed one bug that was exactly this situation; we had
an Access database that kept getting hosed beyond repair because a
printf() in an interrupt handler would occasionally write the string
to the .mdb file instead of stdout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top