![]() |
combinations programm
hello again..
i want to make a programm to find all the combinations of n numbers choosing the k of them for example [1 2 3 4 5] the combinations of two of them are 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 the combinations of 3 numbers of them are 1 2 3 1 2 4 1 2 5 1 3 4 1 3 5 1 4 5 2 3 4 2 3 5 2 4 5 3 4 5 i have made this programm that it is close to find the write solution but i cannot go farther please i want help.. if you can improve my programm or suggest me something already done.. Code:
|
Re: combinations programm
Does your program compile without errors/warnings?
If not please post the complete error/warning messages. If it does compile, what is your program doing wrong? What were your inputs? What did the program output? What did you expect? Jim |
Re: combinations programm
it compiles but here is the difference of what i want and what i get
must be ------and i find 1 4--------------1 4 1 6--------------1 4 1 7--------------1 4 1 9--------------1 4 4 6--------------4 4 4 7--------------4 4 4 9--------------4 4 6 7--------------6 4 6 9--------------6 4 7 9--------------7 4 it is difficult to do this it is difficult the logic..i think only a very good programmer could do that.. and i am not |
Re: combinations programm
the numbers are 1,4,6,7,9 and i want the combinations with k=2
|
Re: combinations programm
If you want a fixed depth then do it with nested for loops which is by far the simplest solution, e.g.
Code:
for (int i=0; i<5; i++)Variable depth is more tricky but can be solved with recursion and a second array to mark whether or not a number has been "seen": Code:
int arr[]={1,4,6,7,9}; |
Re: combinations programm
i found this that works..
Code:
|
Re: combinations programm
So you:
Quote:
Quote:
Jim |
Re: combinations programm
my friend my work is not to do this but i must use this to do my work..
thank you for your time and for your help!! |
| All times are GMT +5.5. The time now is 07:22. |