判定方法为定义一个除数,让它自增,能被两数整除时将其值传给gcd
//自增
int num=1;
while(num<=num1&&num<=num2){
num++;
}
//求两数最大公约数
int num=1;
int gcd=1;
while(num<=num1&&num<=num2){
if(num1%num==0&&num2%num==0)
gcd=num;
num++;
}
判定方法为定义一个除数,让它自增,能被两数整除时将其值传给gcd
//自增
int num=1;
while(num<=num1&&num<=num2){
num++;
}
//求两数最大公约数
int num=1;
int gcd=1;
while(num<=num1&&num<=num2){
if(num1%num==0&&num2%num==0)
gcd=num;
num++;
}