求最大公约数算法 Posted on 2015-05-07 | In Algorithm | 伪代码如下: 123456Algorithm gcd(integerOne, integerTwo) if (integerOne % integerTwo == 0) result = intergerTwo else result = gcd(integerTwo, integerOne % integerTwo) return result C 代码: 123456789101112131415161718#include <Math.h>int gcd(int n1, int n2){ int nOne = fabs(n1); int nTwo = fabs(n2); if (nOne == 0) return nTwo; if (nTwo == 0) return nOne; int result; if (nOne % nTwo == 0) result = nTwo; else result = gcd(nTwo, nOne % nTwo); return result;}