用递归法实现求取两个整数的最大公因子

[复制链接]
查看11 | 回复1 | 2007-4-29 09:29:50 | 显示全部楼层 |阅读模式
mian函数里的代码int a[2];printf("请输入两个整数:");for(int i=0;ib?b:a;for(int i=c;i<=k;i++) {
if((a%i+b%i)==0)
{
get(a,b,i);
}
} return c;}
回复

使用道具 举报

千问 | 2007-4-29 09:29:50 | 显示全部楼层
#include"stdio.h"int fac(int a,int b){ int m;if(a%b==0)m=b;else m=fac(b,a%b);return m;}void main(){ int a,b,m; printf("please input two number:"); scanf("%d%d",&a,&b); if(a<b) {m=a;a=b;b=m;}printf("the max common factor is:%d\n",fac(a,b));}递归我也不太会,还好题不算难,算法用的是辗转求余法
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行