| | |
recursive algorithm
![]() |
•
•
Join Date: Jul 2004
Posts: 6
Reputation:
Solved Threads: 0
i'm having a problem with below recursive code.
there are 4 chars stored in a array, 'a', 'b', 'c', 'd'. input is between 1 and 16, and output should look like this:
when input is 1:
a
b
c
d
when iput is 2:
aa
ab
ac
ad
ba
bb
bc
bd
ca
cb
cc
cd
da
db
dc
dd
and so on...
here is the code i'v been working with:
where should i change to make it work?
there are 4 chars stored in a array, 'a', 'b', 'c', 'd'. input is between 1 and 16, and output should look like this:
when input is 1:
a
b
c
d
when iput is 2:
aa
ab
ac
ad
ba
bb
bc
bd
ca
cb
cc
cd
da
db
dc
dd
and so on...
here is the code i'v been working with:
C Syntax (Toggle Plain Text)
void f(int x, int num) { int i; char a[4] = {'a', 'b', 'c', 'd'}; char temp[16]; if(num == 0) return; else for(i = 0; i < 4; i++) { temp[x] = a[i]; f(x + 1, num - 1); temp[x + 1] = '\0'; printf("%s\n", temp); } }
where should i change to make it work?
![]() |
Similar Threads
- Recursive algorithm (C++)
- Time Complexity of Recursive Algorithm (Computer Science)
- algorithm problem with recursion (Java)
- recursive algorithm (C++)
- recursive findaverage function for Binary search tree (C)
- Can you guys help me? about Quick Sort Algorithm (C)
Other Threads in the C Forum
- Previous Thread: File parsing in 'C'
- Next Thread: Reversive Array/Integer
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hardware highest homework i/o ide inches intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi





