{x = A, y = B}(adsbygoogle = window.adsbygoogle || []).push({});

begin

while x != y do

if x < y

then y := y - x

else x := x - y

end

{x = gcd(A, B)}

How do I prove that the program above is correct? A and B are whole numbers and gcd(A, B) stands for Greatest Commom Divisor. What's the best method for proving that it computes the gcd of A and B? It's not written in any specific language.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Proving a program

**Physics Forums | Science Articles, Homework Help, Discussion**