![]() |
|
#1
|
|||
|
|||
help in c++ recursive functionshad an assignment where in i have to create a recursive function program
given a base number and an exponent. for example: power(10,2)= 100 10 is the base and 2 is the exponent; here's what ive done so far: CPP / C++ / C Code:
pls. help me locate the error in the code. your help will be much appreciated. thanx in advance!!! Last edited by LuciWiz : 13-Jul-2005 at 07:23.
Reason: Please insert your C++ code betweend [c++] & [/c++] tags
|
|||
|
#2
|
|||
|
|||
|
Recursion can be viewed as an alternate form of a loop. Just like a loop needs a terminating condition, so does the recursion. Each time you recurse, the function should be passed a value that converges to this condition (for example, a base that is successively one less than the previous and a check for a base that is greater than zero).
On your next spin, it might be good to use standard C++ (not pre-standard <iostream.h> headers, for example). And an implicitly declared main is over a decade out of date as well. And you don't need to use a global variable. |
|
#3
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
Hope this helps. Matthew Edit: Oops, I am rather late! |
|
#4
|
|||
|
|||
ode for Power FunctionHi,
I just saw your code and was wondering on 2 count. 1) In the code for you power fuction will go on an infinite loop as there is no Exit condition. 2) In your main function you are not capturing the value that is being returned by the main function. You need to capture the value that is being returned by the function. And also the concept of using Global varaibles is a old concept and is not a good Object Orientation Practise. The following code should work: CPP / C++ / C Code:
This has been tested in VC++ Compiler. and i guess this shld work in all Windows based Compilers. Regards Prasanth |
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
Re: help in c++ recursive functionsi should make a recursive programm
that print the partition of the number N that's mean for N=4 4 31 22 211 1111 if N=5 5 41 32 311 221 2111 11111 if N=6 6 51 42 411 33 321 3111 222 2211 21111 111111 |
|
#7
|
|||
|
|||
Re: ode for Power FunctionQuote:
Gives an error for Cygwin g++ (on Windows XP) and, therefore, will not compile: Code:
Regards, Dave |
|
#8
|
|||
|
|||
Re: help in c++ recursive functionsWelcome luaik.
First of all, why would you want to post a reply to a very old thread rather than start a new thread for your problem? Second: __________________
Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with. |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| friend functions error | CaptnB | C++ Forum | 2 | 12-Jun-2006 13:39 |
| Major problem with recursive function, help.. | kakamuti | C Programming Language | 4 | 19-Dec-2004 07:47 |
| Understanding Recursive Functions | Nexa | C++ Forum | 5 | 19-Nov-2004 11:51 |
| conflict between printf and stdarg.h va functions | mirizar | C Programming Language | 3 | 12-Jul-2004 08:11 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The