Thread: The Euclidean algorithm

  1. #1
    Registered User
    Join Date
    Oct 2009

    The Euclidean algorithm

    hey guys ...
    i am a new member and i want some help in a pseudo-code
    i was asked to write a pseudo-code for the Euclidean algorithm
    this was the question
    " The euclidean algorithm determines the greatest common divisor (GCD) of two positive numbers by repatedly replacing the larger number with the result of subtracting the smaller one from it until the two numbers are equal"

    And this is my Answer
    Get x,y //x,y any numbers
    set gcd to 0 //gcd = Great Common divisor
    if (x>0) and (y>0)
       then if (x-y) > 0
                 then while (x>y)
                        { set gcd to ( gcd + (x-y) )
                           set x to x-y
                         print " the GCD" + gcd
                  else if (y-x) > 0
                        then while (y>x)
                               { set gcd to ( gcd + (y-x) )
                                 set y to (y-x)
                                print "the GCD "+ gcd
                          else print " the numbers are equal"
                          end if 
                   end if
       else print " There is a negative number at least "
    end if
    Is this Code correct??
    and is it not could any one tell me why it is not correct and what is the correct code ??
    i'm waiting guys

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Wrong forum, could someone move this?

    What you wrote isn't even C/C++, it looks like BASIC.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM