![]() |
|
#1
|
|||
|
|||
Understanding Recursive FunctionsI do not really understand what is being asked here, would anybody like to offer there help to help me understand this word problem. Any help would be appreciated.
The greatest common divisor of integers x and y is the largest interger that evenly divides both x and y. Write a recursive function gcd that returns the greatest common divisor of x and y, which is defined recursively as follows: If y is equal to 0, then gcd(x,y) is x: otherwise gcd(x,y) is gcd(y, x % y), where % is the modulus operator. Thanks, Nexa |
|
#2
|
||||
|
||||
|
HI Nexa. I get a kick out of recursive functions. A recursive function simply keeps calling itself in a nested fashion until something inside the function tells it to return.
This function can be coded quite easily based upon the given alogorithm: CPP / C++ / C Code:
You need to test that because I didn't Also, I am leaving the commenting to you so you can figure out what is happening.__________________
The best damn Sports Blog period. |
|
#3
|
|||
|
|||
|
Thanks, dssmith, Any help at this point is better than no help.
|
|
#4
|
|||
|
|||
Ahhhh!, Can you say hit a brick wall. I know I probably have something so simple that I am not seeing here, but truth is I am so lost right now. My text book it not offering much help. Here is what I have so far, all I ask is how do I get my function to work correctly. When I run it, it completely skips my function and exits the program. CPP / C++ / C Code:
Last edited by Nexa : 18-Nov-2004 at 23:08.
Reason: Make code read in c++ format
|
|
#5
|
|||
|
|||
|
I guess you forgot to call your function in main().
. Function needs to be called for its code to be executed. You also need to print the value returned by gcd() function in main() |
|
#6
|
|||
|
|||
|
Thanks much!!!! Nexa |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please help with functions... | brookeville | C++ Forum | 36 | 05-Nov-2004 01:23 |
| variables in functions help | dopee | MySQL / PHP Forum | 5 | 16-Oct-2004 21:20 |
| conflict between printf and stdarg.h va functions | mirizar | C Programming Language | 3 | 12-Jul-2004 09:11 |
| Understanding functions | tommy69 | C Programming Language | 15 | 15-Mar-2004 18:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The