1个回答
展开全部
我只对第五题感兴趣就贴在这里了,其他的很简单你抄你同学的吧。
#include "stdio.h"
#define max(x,y) x>y?x:y
#define min(x,y) x>y?y:x
//循环实现
int gcd_recycle(int x, int y){
while(true){
int max = max(x,y);
int min = min(x,y);
int aa = max%min;
if(0 == aa)
return min;
else
x=min,y=aa;
}
}
//递归实现
int gcd_recurse(int x, int y){
int max = max(x,y);
int min = min(x,y);
int aa = max%min;
if(0 == aa)
return min;
else
return gcd_recurse(min, aa);
}
int main()
{
int x,y;
printf("Please input two positive integers:\n");
printf("x:");
scanf("%d",&x);
printf("y:");
scanf("%d",&y);
printf("最大公约数为:循环实现--%d 递归实现--%d",gcd_recycle(x,y), gcd_recurse(x, y));
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询