A
Al Balmer
So you can cut and pasteWhy use a variable then?
So you can cut and pasteWhy use a variable then?
hi all,
could any one solve the following C program. If any one knows the
answer please post it
Ques:
A C function that will print 1 to N one per each line on the
stdout , where N is a int parameter to the function. The function
should not
use while, for, do-while loops, goto statement, recursion, and switch
statement.
prady wrote On 11/20/07 09:55,:
Here you go. Note that this version only works for
`int' values up to the guaranteed minimum of 32767; if
your implementation supports larger `int' values, make
the obvious modifications.
typedef void(o)(int,int),O;O theFunction(int N){o OO;OO(00,N
);}O Oo(int poq,int puq){o OoQ;OoQ(puq,poq);OoQ(++puq,poq);}
O oO(int qup,int qpu){Oo(qpu,qup++);Oo(qpu,++qup);}O o0(int\
pqu,int ppq){ oO(ppq,pqu);oO(ppq+04,pqu);}O O0(int puq,int\
poq){o0(poq,puq);o0 (poq,puq+010);}O oo(int qop,int qpp){O0
(qpp,qop);O0(qpp+16,qop);}O QO(int ppq,int oqu){oo(oqu,ppq);
oo(oqu,ppq+32);}O Qo(int poq,int puq){QO(puq,poq);QO(puq+01\
00,poq);}O QQ(int qup,int qpu){Qo(qpu,qup );Qo(qpu,qup+128);
}O Q0(int pqu,int puq){QQ(puq,pqu);QQ(puq+256,pqu );}O OQ(i\
nt uqp,int poq){Q0(poq,uqp);Q0(poq,uqp+512);}O oQ(int qop, \
int puq){OQ(puq,qop);OQ(puq+1024,qop);}O oOo(int puq,int poq
){oQ(poq ,puq);oQ(poq,puq+2048);}O OoO(int qpu,int qup){oOo(
qup,qpu);oOo(qup+ 4096,qpu);}O OO(int ppq,int pqu){OoO(pqu,\
ppq);OoO(pqu,ppq+16384);}
#include <stdio.h>
O OoQ(int qpp,int poq){if(qpp&!(qpp>poq))printf("%d\n",qpp);}
Eric Sosman wrote On 11/20/07 15:16,:
Oh, drat! Silly typo: Fix the bug by changing `&'
to `&&', of course.
Eric Sosman wrote On 11/20/07 15:16,:
Oh, drat! Silly typo: Fix the bug by changing `&'
to `&&', of course.
I'm reminded of an excerpt from _Learning Perl_:Eric said:Eric Sosman wrote On 11/20/07 15:16,:
Oh, drat! Silly typo: Fix the bug by changing `&'
to `&&', of course.
hi all,
could any one solve the following C program. If any one knows the
answer please post it
Ques:
A C function that will print 1 to N one per each line on the
stdout , where N is a int parameter to the function. The function
should not
use while, for, do-while loops, goto statement, recursion, and switch
statement.
With that fixed, your function is still missing the numbers from 8192 to
16383.
[/QUOTE]Can you see any point to the prohibition of switch statements?
To encourage students to think "out of the box" pretty much like any
teaching course.
prady said:A C function that will print 1 to N one per each line on the
stdout , where N is a int parameter to the function. The function
should not
use while, for, do-while loops, goto statement, recursion, and switch
statement.
Richard said:That leaves non-syntactic control constructs, of which there is only
one: setjmp()/longjmp(). And presumably that is the expected answer.
That actually is the point why I heavily dislike the
setjmp()/longjmp()-version: because they *expect* you to come up with
it. Some teacher comes up with an incredibly bizzare assignment, makes
ridiculous restrictions on what constructs are okay and which aren't and
then still tries to force you to think the way he does.
[comp.lang.c] Al Balmer said:Why use a variable then?
So you can cut and paste
Johannes said:[...]
If any teacher in the world would dare to give no points to a solution
like Eric's, I'd like to tear him to pieces.
But I very much believe
there are many of them. Self-declared C-"programmers" who think their
solutions are bleeding edge. I'm so sick of them.
Probably because I was confronted with a lot of these people at college.
Horrible, horrible experiences coming up. Yeah well, now I shared them ;-)
prady said:hi all,
could any one solve the following C program. If any one knows the
answer please post it
Ques:
A C function that will print 1 to N one per each line on the
stdout , where N is a int parameter to the function. The function
should not
use while, for, do-while loops, goto statement, recursion, and switch
statement.
Peter said:Recursion is disallowed, but a function can call a separate but
otherwise identical function.
Chris said:Peter said:Recursion is disallowed, but a function can call a separate but
otherwise identical function.
Thereby failing the requirement "/A/ C function" [emphasis mine].
Just the one, Mrs Wembley.
hi all,
could any one solve the following C program. If any one knows the
answer please post it
Ques:
A C function that will print 1 to N one per each line on the
stdout , where N is a int parameter to the function. The function
should not
use while, for, do-while loops, goto statement, recursion, and switch
statement.
could any one solve the following C program. If any one knows the
answer please post it
Ques:
A C function that will print 1 to N one per each line on the
stdout , where N is a int parameter to the function. The function
should not
use while, for, do-while loops, goto statement, recursion, and switch
statement.
Peter said:Chris said:Peter said:Recursion is disallowed, but a function can call a separate but
otherwise identical function.
Thereby failing the requirement "/A/ C function" [emphasis mine]. Just
the one, Mrs Wembley.
I'm pretty sure you are permitted to use additional functions, unless
you plan to avoid uses of printf() and friends.
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.