this is a question for all of u to try
write a program to print 1 to n numbers without using loops
without using test conditions, control structures?
this is a question for all of u to try
write a program to print 1 to n numbers without using loops
without using test conditions, control structures?
Here's a question.
Try doing your own homework?
Naturally I have to agree. Show us your attempt, blah blah. I should just make this my tag line, so I don't have to type it every single day to people who expect their homework done for them.
It'll be interesting to see how they expect you to fulfill this neat little piece of the puzzle though:
Quzah.without using test conditions
Hope is the first step on the road to disappointment.
It's not that difficult problem...
I suppose it's an exersice about recursion.
Code:#include <stdio.h> void writeNumbers( int ); int n; int main() { scanf( "%d", &n ); writeNumbers( 1 ); return 0; } void writeNumbers( int i ) { if( i == n+1 ) printf( "\n" ); else{ printf( "%d ", i ); writeNumbers( ++i ); } }
This would be considered a "test condition".if( i == n+1 )
Furthermore, you're missing the entire point of the board. The board is not here to do people's homework for them. Thanks for defeting the purpose of the board.
Quzah.
Hope is the first step on the road to disappointment.
>This would be considered a "test condition".
Oh God !!! Forgot about this one!!
Well then, pal tell them ( the people who told you the problem) to reconsider their initiall thoughts. It's a silly problem with no solution. Tell them this, and then tell them that i told you that, and everything is gonna be fine. Go without doing your homework, I give you the permission
Here's mine:Originally posted by debuger2004
write a program to print 1 to n numbers without using loops
without using test conditions, control structures?
Code:#include <stdio.h> int main(void) { puts("1 to n numbers"); return 0; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I love it. That's what I call getting by on a technicality. Technicly, that is exactly what they require, to the letter.
Salem had an amusing solution, maybe he'll send it to you. Mine was also amusing, at least I thought so. Basicly it runs you out of stack space, telling you that N represents the amount of stack space you have, divided by the overhead of the function call itself, since the described requirements don't say that N is something the user inputs. It simply states that it needs to print 1 to N.
Quzah.
Hope is the first step on the road to disappointment.
I think you should post 'em here. I like interesting solutions to simple problems
debuger2004: Are you from the future, as your name suggests? Can't you see the answer sheet, seeing as this homework is like a year old to you?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thank you for your valuable solutions.
the loop can be removed by recursion
and the test condition by bitwise operators used as a short circuit operator
thanks
again
Yea post the answer, I was playing with it last night and couldn't figure it out. Would love to see the answer.
Here are some answers http://www.wikiservice.at/dse/wiki.c...kSport_C_CPP_1.
I like this one
Or do a search on comp.lang.c.Code:#include <stdio.h> int main(int x,char* y[]) { return y&&main(0,0)||(printf("%d ",++x)-3&&main(x,0),printf("%d ",x)); }
>>http://cboard.cprogramming.com/showt...threadid=40816
I take it we're talking about that thread? If so, please don't new threads about the same topic
>>y&&main(0,0)
This is still a test condition, imo, it just doesn't have the "if" statement.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
[edit]Removed recursive main call rant.[/edit]Originally posted by Hammer
>>[url]>>y&&main(0,0)
This is still a test condition, imo, it just doesn't have the "if" statement.
[edit2]Nevermind. I was right. I misread Salem's post.[/edit2]
[edit3]Adding original rant:
Not to mention the fact that recursively calling main no longer legal. I mean it's all neat and fun to make interesting challenges, but I would at least hope they could come up with a legal solution.
[/edit3]
Somehow I don't think the '-ansi' flag would be happy. Don't even think about '-pedantic'.
Quzah.
Last edited by quzah; 06-19-2003 at 02:18 PM.
Hope is the first step on the road to disappointment.
>>>Is it time for my answer?
*** drum roll ***
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]