![]() |
|
#1
|
|||
|
|||
Recursion functionI am having a lot of problem with recursive functions which i'v recently started learning.
The problem: The user gives 2 int inputs, eg 1 and 1. The output should b a series like this 1 1 2 3 5 8 13 21 34 ...till 50 i.e the next number is the sum of the previous 2 numbers.Recursive functions are a bit confusing and since i am a beginner, i would be glad if you could help me. |
|||
|
#2
|
||||
|
||||
Re: Recursion functionSure, we'd be glad to help. But this isn't the Psychic Programmer's Forum. unless you show us what you've done and explained what the problem is, we're at a loss to help.
Read the Guidelines __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#3
|
|||
|
|||
Re: Recursion functionCPP / C++ / C Code:
Code:
The output gives 1. Whereas i should be getting : 11235813...............till less than 50 Last edited by admin II : 20-Mar-2008 at 05:20.
Reason: Please surround your C code with [cpp] your code [/cpp]
|
|
#4
|
|||
|
|||
Re: Recursion functionI feel that i have probably placed the printf in the wrong place,or there has been some problem with the allignment of the codes. I dont understand what i have done wrong. Please help me if you can. it would be very kind of you.
|
|
#5
|
||||
|
||||
Re: Recursion functionNo, it's because when you call rec() the first time, you return and the program ends. You never get a second call to rec().
Execute the code you have by hand. Then rethink your logic in the function. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#6
|
|||
|
|||
Re: Recursion functionhey, Waltp...Im stuck. Please help me out. Even if i place return after calling rec() it gives the same output.
|
|
#7
|
||||
|
||||
Re: Recursion functionAnd what did you come up with when you did your re-think? Did you follow your code as I suggested? What happened? What did you find out?
__________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#8
|
|||
|
|||
Re: Recursion functionCPP / C++ / C Code:
i finally came up with this and it works...thanku anyways.. Last edited by admin II : 24-Mar-2008 at 11:57.
Reason: Please surround your C code with [cpp] your code [/cpp]
|
|
#9
|
||||
|
||||
Re: Recursion functioncheck it out
CPP / C++ / C Code:
Last edited by admin II : 29-Mar-2008 at 16:42.
Reason: Please surround your C++ code with [cpp] your code [/cpp]
|
|
#10
|
|||
|
|||
Re: Recursion functionDude...Sabreen....u r basically working with a very common problem in Computer Science.....it is called "Fibonacci series". Just Google it up....see the algorithm for that series...try to understand it, try to get the meaning of recursive functions....thats it....U will be the one then...
Good Luck |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| Flex and bison coding | lucky88star | C++ Forum | 5 | 24-Dec-2007 12:57 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 17:19 |
| Message Class | TransformedBG | C++ Forum | 5 | 29-Nov-2006 22:28 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The