Were usng DrRacket in class The famous computer scientist Ed
We\'re usng DrRacket in class.
The famous computer scientist, Edsger Dijkstra, made the
following observations for m and n >= 1:
1. If m = n, then the greatest common divisor of m and n is m.
2. If m > n, then the greatest common divisor of m and n is
the greatest divisor of m-n and n.
Based on these observations, implement a function to compute
the greatest common divisor of two given numbers >= 1. Follow
all the steps of the design recipe. and write the termination argument.
Solution
int GCD(int m,int n){
while(m!=n){ // while loop with termination argument m==n
if(m>n)
return GCD(m-n,n);// If m > n, then the gcd of m and n is the greatest divisor of m-n and n.
else
return GCD(m,n-m);
}
return m;
}
