Thread: question ?

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    21

    Smile question ?

    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?

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    25
    Here's a question.

    Try doing your own homework?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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:
    without using test conditions
    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Banned
    Join Date
    May 2003
    Posts
    124
    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 );
    	}
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    if( i == n+1 )
    This would be considered a "test condition".

    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.

  6. #6
    Banned
    Join Date
    May 2003
    Posts
    124
    >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

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: question ?

    Originally posted by debuger2004
    write a program to print 1 to n numbers without using loops
    without using test conditions, control structures?
    Here's mine:
    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]

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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]

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    21

    review to my previous question

    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

  11. #11
    .........
    Join Date
    Nov 2002
    Posts
    303
    Yea post the answer, I was playing with it last night and couldn't figure it out. Would love to see the answer.

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    148
    Here are some answers http://www.wikiservice.at/dse/wiki.c...kSport_C_CPP_1.

    I like this one
    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));
    }
    Or do a search on comp.lang.c.

  13. #13
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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]

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Hammer
    >>[url]>>y&&main(0,0)
    This is still a test condition, imo, it just doesn't have the "if" statement.
    [edit]Removed recursive main call rant.[/edit]
    [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.

  15. #15
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>>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]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM