/ Published in: C
Let m and n be variables containing the two numbers.
If n is 0, then stop : m contains the GCD
Otherwise, compute the remainder when m is divided by n.
Copy n into m and copy the remainder into n.
Then repeat the process, starting with testing whether n is 0.
If n is 0, then stop : m contains the GCD
Otherwise, compute the remainder when m is divided by n.
Copy n into m and copy the remainder into n.
Then repeat the process, starting with testing whether n is 0.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//calculate Greatest Common Divisor(GCD) #include <stdio.h> #include <stdbool.h> int main (int argc, const char * argv[]) { // insert code here... //declarations int n , m; int gcd; int remainder; //get user input //calculations while (n != 0) { remainder = m % n; m = n; n = remainder; } gcd = m; //show results }