1
#include
<
iostream.h
>
2 int enchild( int m, int n); // 函数声明
3
4 void main()
5 {
6 int m,n;
7 cout << " 正整数1: " ;
8 cin >> m;
9 cout << " 正整数2: " ;
10 cin >> n;
11 cout << m << " 与 " << n << " 的最大公因子为: " << enchild(m,n) << endl;
12 }
13 /*
14 *欧几里德算法
15 *功能:求两个正整数的最大公因子
16 */
17 int enchild( int m, int n)
18 {
19 int r;
20 do
21 {
22 r = m % n;
23 m = n;
24 n = r;
25
26 }
27 while (r);
28 return m;
29 }
2 int enchild( int m, int n); // 函数声明
3
4 void main()
5 {
6 int m,n;
7 cout << " 正整数1: " ;
8 cin >> m;
9 cout << " 正整数2: " ;
10 cin >> n;
11 cout << m << " 与 " << n << " 的最大公因子为: " << enchild(m,n) << endl;
12 }
13 /*
14 *欧几里德算法
15 *功能:求两个正整数的最大公因子
16 */
17 int enchild( int m, int n)
18 {
19 int r;
20 do
21 {
22 r = m % n;
23 m = n;
24 n = r;
25
26 }
27 while (r);
28 return m;
29 }