样例输入
5 7
样例输出
1
#include <stdio.h>
int gcd (int a,int b)
{
int i=1,last=1,min=1;
if(a<b)
min = a;
else
min = b;
while(i<=min)
{
if(a%i==0 && b%i==0)
last = i;
i++;
}
return last;
}
int main(void)
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d", gcd(a, b));
return 0;
}
最后
以上就是义气白猫最近收集整理的关于编写一个函数,在主函数从键盘输入两个正整数,调用该函数求取这两个数的最大公约数(最大公因数)。的全部内容,更多相关编写一个函数,在主函数从键盘输入两个正整数,调用该函数求取这两个数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复