JurajUQU
asked on
Recursive algorithm
I haven't been programming in ages and doing couple of online courses gave me some basic but still can't figure out how to do a simple recursion for an algorythm I want to do.
I have a field of 9 digits that goes recursively through all the options (0 or 1) ie
000000000
100000000
010000000
...
111111111
I've tried i++ but then it goes through once and doesn't give me all of the 45 options, but rather just 9.
What I want out of it is to input number 13 let's say, which would give me appropriate result: 100100000
It might be a stupid question but I really don't know how to tackle it.
Thanks
I have a field of 9 digits that goes recursively through all the options (0 or 1) ie
000000000
100000000
010000000
...
111111111
I've tried i++ but then it goes through once and doesn't give me all of the 45 options, but rather just 9.
What I want out of it is to input number 13 let's say, which would give me appropriate result: 100100000
It might be a stupid question but I really don't know how to tackle it.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you David.
bool is true or false but I'd like to scale it up later. Would I just change it to int[8] let's say and will it work as well?
bool is true or false but I'd like to scale it up later. Would I just change it to int[8] let's say and will it work as well?
No, just work in the Main subroutine and change the "test + 4" to the number of digits you want to handle and "test" variable (currently = "0000") to the same number of zeros.
So glad you posted this question....I just realized that it's the last day of the month! Thanks for posting.
ASKER
Here's already 1.7.14 late afternoon :)
I'll have a look and report back
I'll have a look and report back
Really, it's 11:30 here. Experts-Exchange is 10:30. You must be near India (or north of it).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
at the beginning and include the iostream namespace