C Board  

Go Back   C Board > Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards > General AI Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2009, 01:53 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 1
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
Code:
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
the_storm is offline   Reply With Quote
Old 10-28-2009, 03:41 AM   #2
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
Wrong forum, could someone move this?

What you wrote isn't even C/C++, it looks like BASIC.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Implement of a Fast Time Series Evaluation Algorithm BiGreat C Programming 7 12-04-2007 02:30 AM
Euclid Algorithm (extended)Part2 Doubt about pointers - INITIALIZATION nacho4d C Programming 4 12-10-2006 07:08 PM
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM
Request for comments Prelude A Brief History of Cprogramming.com 15 01-02-2004 10:33 AM


All times are GMT -6. The time now is 12:11 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22