作业帮 > 综合 > 作业

题目是这样意思就是求一个数除以另一个数的最大公约数 举个例子 129除以15的最大公约数是3

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/22 21:04:54
题目是这样意思就是求一个数除以另一个数的最大公约数 举个例子 129除以15的最大公约数是3
题目是这样的( 英文
greatest common divisor (gcd),also known as the greatest common factor (gcf),
or highest common factor (hcf),of two integers a and b (a >=b),
is the largest positive integer that divides the numbers without a remainders.
GCD(a,b) is a,if b = 0.Otherwise it is GCD of b and a % b.
例子
GDC (129,15)
129 = 8 * 15 + 9
15 = 1 * 9 + 6
9 = 1 * 6 + 3
6 = 2 * 3 + 0
#include
int gcd(int a,int b)
{
if(b==0)
return a;
else
gcd(b,a%b);
}
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a