Thread: Start on this

  1. #1
    Registered User
    Join Date
    Oct 2006

    Start on this

    Can anyone tell me how to get started on this assignment?

    The greatest common divisor of two positive intergers is the largest interger that divides the numbers exactly. We can write a recursive formula for finding the GCD, given that the two numbers are called a and b, as:

    GCD[a, b] = a, if b = 0
    GCD[a, b]= LCF[b, a%b], if b > 0

    Implement this recursive formula as a recursive C++ function, and write a driver program that allows you to test it interactively.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Start by writing the function prototype. Then add temporary code to return 0 no matter what from the function. Then write the driver program, compiling and testing as you go.

    Then start adding code to the function. Perhaps you could start by implementing the stop case for the recursive function. Then add code that does the work. Keep compiling and testing as you go.

    Then you are done.

  3. #3
    Registered User
    Join Date
    Sep 2001
    // Returns GCD[arg1, arg2]
    int GCD (int arg1, int arg2) {
    	int result;
    	// Do the operations here
    	return result;
    // Returns LCD[arg1, arg2]
    int LCD (int a, int b) {
    	int result;
    	// Do the operations here
    	return result;
    int main (void) {
    	// Implement your driver here.
    	return 0;
    Callou collei we'll code the way
    Of prime numbers and pings!

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    your result is not initialized - your current prototypes return garbage
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. C++ gui for windows where to start
    By prixone in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2006, 11:48 PM
  4. GNOME Desktop won't start (Mandriva)
    By psychopath in forum Tech Board
    Replies: 10
    Last Post: 07-19-2006, 01:21 PM
  5. Start bar color in WinXP
    By confuted in forum Tech Board
    Replies: 4
    Last Post: 05-03-2003, 06:18 AM