![]() |
|
#1
|
|||
|
|||
[c++] number combinationshi everybody! i am trying to write a program that gives all possible combinations of the given digits. i am just not getting the idea how to start. pls help me. suppose, a number 1234 is given, then we should output all combinations such as . 4321,3214,2143,....etc.,.
|
|
#2
|
||||
|
||||
Re: [c++] number combinationsHi balusss,
Welcome to GIDForums. You can do this by using recursion. (I hope you know what is recursion Before we venture into the actual program deeply, can you write a simple recursion function for finding out the factorial of a given number? Cheers, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: [c++] number combinationsthank u parameshji,
i know recursion and did quite a lot of exercises on it. i also have read ur reply to 'netnut' on the permutations of a given word. the elaborate answer infact made me more affiliated to u. but, u see, i didn't somehow catch what i have to do with 'next' and 'place'. i have read the elaboration. pls probe me a little more so that i get to it. thank u for your concern in replying. |
|
#4
|
|||
|
|||
Re: [c++] number combinationsi am new to this site. having lil problems to browse here and there
|
|
#5
|
||||
|
||||
Re: [c++] number combinationsHi balusss,
Call me Paramesh. Not parameshji. Quote:
1. We start with an array of ints containg the values {1 2 3 ... N} (set up in the main() program before calling the recursive function). So, let the array be: numbers[4] = {1, 2, 3, 4}; What is the place: An argument to the recursive function that indicates the current position within the array where we are going to put the next element. When we get into the recursive function with "place" equal to N, we know that all of the elements of the current permutation are there, ready to be printed. So, the function looks like this: CPP / C++ / C Code:
CPP / C++ / C Code:
So, consider the case of 3, and using pencil and paper( remember --- no code yet Once you get familiar with the logic, then go to the program. Once you finish this part we can switch to your original program. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#6
|
|||
|
|||
Re: [c++] number combinationshi balusss, i think that both of us are in the same boat. The difference between u and me is that u r working with numbers and I with strings. So lets see who crosses the line first (line here means the correct code). !! All the best
|
|
#7
|
|||
|
|||
Re: [c++] number combinationsYou're problems are over Balusss.
Yes...you read that right. My code is completed and working fine, and since I was working with strings your problem is also sorted, 'cuz you enter the digits as a string and all the possible combinations are printed. |
|
#8
|
|||
|
|||
Re: [c++] number combinationsfirst of all,
i thank mr.paramesh for making the difference. i got it right in the saturday eve itself. and the program is working fine. i also made it a template and stored it in my libraries. everything is well. and i am happy mr.netnut too 'crossed the line' on the same day. thanks paramesh and i owe you for that. |
|
#9
|
|||
|
|||
Re: [c++] number combinationsand one more thing. how do get the 'repetitions'??????? that is if 123 is given, how can i get 122, 133, 111,222,333 etc.,?????? will any simple modification to the code i have written for 'combinations' work?
|
Recent GIDBlog
Observations of Iraq by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help with my Cards Program (C++) | krisopotamus | C++ Forum | 2 | 06-Oct-2005 16:48 |
| Knights Tour - Reloaded . | kobi_hikri | C Programming Language | 12 | 03-Oct-2005 12:15 |
| Roman to decimal to roman | SpudNuts | C++ Forum | 2 | 16-Feb-2005 19:44 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Array..... | chriskan76 | C Programming Language | 4 | 18-Oct-2004 14:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The