欧几里德算法
1 /*
2 欧几里德算法:辗转求余
3 原理: gcd(a,b)=gcd(b,a mod b)
4 当b为0时,两数的最大公约数即为a
5 getchar()会接受前一个scanf的回车符
6 */
7 #include<stdio.h>
8 unsigned
int Gcd(unsigned
int M,unsigned
int N)
9 {
10 unsigned
int Rem;
11 while(N >
0)
12 {
13 Rem = M %
N;
14 M =
N;
15 N =
Rem;
16 }
17 return M;
18 }
19 int main(
void)
20 {
21 int a,b;
22 scanf(
"%d %d",&a,&
b);
23 printf(
"the greatest common factor of %d and %d is ",a,b);
24 printf(
"%d\n",Gcd(a,b));
25 return 0;
26 }
来自https://baike.baidu.com/item/欧几里德算法/9002848?fr=aladdin
转载于:https://www.cnblogs.com/Blue-Keroro/p/8608474.html
相关资源:易语言约分算法源码