普通算法(欧几里得辗转相除)
1 #include <stdio.h> 2 unsigned int Gcd(unsigned int a,unsigned int b) 3 { 4 unsigned int remainder ; 5 while(b > 0) 6 { 7 remainder = a % b; 8 a = b; //第二部:在下一次循环中,非零余数给了a 9 b = remainder; //第一步:最后一次非零余数先给b 10 } 11 return a; //所以最后返回a 12 } 13 int main () 14 { 15 unsigned int a = 50; 16 unsigned int b = 15; 17 printf("%d",Gcd(a,b)); 18 19 }