/ 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.
Expand |
Embed | Plain Text
//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 scanf("%d%d", &n, &m); //calculations while (n != 0) { remainder = m % n; m = n; n = remainder; } gcd = m; //show results }
You need to login to post a comment.
