『代码』··By/蜜汁炒酸奶

求最大公约数

/*
功能:求最大公约数
日期:2013-06-19
*/

#include<stdio.h>
#include<stdlib.h>
int gcd(int m,int n);
int main(void)
{
   int num1,num2;
   printf("请输入两个数字:");
   scanf("%d %d",&num1,&num2);

   printf("最大公约数为:%dn",gcd(num1,num2));
   system("pause");
   return 0;
}
/************************************************************************
函数名:gcd
功能:求最大公约数
参数:int m  待求数num1
      int n  待求数num2
返回值:两值的最大公约数
************************************************************************/
int gcd(int m,int n)
{
   if(m==n)
   {
        return m;
   }
   else
   {
       if (m>n)
       {
		   gcd(m-n,n);
       }
	   else
	   {
	        gcd(m,n-m);
	   }
   }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

预览
Loading comments...
0 条评论

暂无数据

example
预览