Thread: Please help.

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    2

    Please help.

    I want to do this with recursion
    If I enter 5
    output will be
    5=1+1+1+1+1
    5=1+1+1+2
    5=1+1+3
    5=1+2+2
    5=2+3
    .....
    .....
    .....

    Please give any idea or code.
    Last edited by arnabc; 09-07-2007 at 11:20 AM.

  2. #2
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    What do you have so far?
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    34

    Thumbs up

    should the output give
    5=1+4
    also ??
    if not
    how did u specify that only those outputs have to be shown??

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    2
    Quote Originally Posted by shuaib.akram View Post
    should the output give
    5=1+4
    also ??
    if not
    how did u specify that only those outputs have to be shown??
    ya it will also give 1+4

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Write out a few steps
    1 is well, just 1

    2 is 1 + 1

    3 would be
    2 + 1
    1 + 2
    1 + 1 + 1

    4 - well, you get the idea.

    Once you've got some idea of the pattern, then you can think in terms of what the "n-1" recursive step is going to look like.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed