You have been given a task to produce all the numbers which add up to n. Somebody else has had the same problem before. You will need a method which takes two parameters to start with. Go through your numbers and decide what you actually want to print out. If you have 4, 2, how do you get it to print 44, 43, 42, 41, and not 444?
Say, "It should start with two numbers, then adding one number leaves one to go." "It should continue with one number, then adding one number leaves none to go." "Then it stops."
Then tell us what you have got. Good luck.
Added this bit: When I said "you have been given a task . . ." I ought to have said that what you posted finds all the numbers which add up to n. I tried it and it works nicely. Have you been through it to see how the recursion and iteration work?[/edit] [ February 15, 2008: Message edited by: Campbell Ritchie ]
i cant understand what do you meen by adding one number and having one to go there you told me to get two numbers as the question says i soppose that one represents the range of numbers till what numbers to go the other is about to how many objects to have in each group
i cand understand what i am supposed to add to ???
Sorry, I confused you earlier; suggest you ask one of the moderators on this board to consider transferring this thread to beginners'.
Be grateful for small mercies; somebody else has been given "spiral filling." I think he posted on this board today. That seems far more difficult. I tried "spiral filling" and failed.
What you posted first looks the same as somebody else posted here about 6 months ago. If you give it 4 as an input it prints 4 3 1 2 2 2 1 1 1 1 1 1 which means the integers greater than 0 which add up to 4. Obviously what you are getting now is an improvement. You need to pass it two numbers, 4 and 2, where "4" means "start with the number 4," and "2" means, "print 2 numbers in the output." You seem to have got that bit to work.
Suggest you post what you have got, and tell us how it works, then see what changes are needed.
no i dont know how to change it i set with a penn and paper i made the steps for the input 5 i got the correct resolt i got to the conclution that some how the "for" responsible here for each step (each groop of numbers which sums to 5)
but i still dont have any clue about how to change it so it will produce the resolt i want regarding this question
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad: