您的位置:首页 > 其它

超强算法-求任意二个数的最大公约数

2007-05-21 11:18 253 查看
using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace AlgorithmBase
6{
7 public class MaxCommonDivisor
8 {
9 public static int GetMaxCommonDivisor(int m,int n)
10 {
11 if (m < n)
12 {
13 int temp = m;
14 m = n;
15 n = temp;
16 }
17
18 int r = m % n;
19
20 while (r != 0)
21 {
22 m = n;
23 n = r;
24 r = m % n;
25 }
26
27 return n;
28 }
29 }
30}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: