帮助,当我在执行代码后在终端中引入16104
和3216
时:
#include <iostream>
using namespace std;
int main () {
int a, b;
cin >> a >> b;
int r=0;
int i=0;
while (i<a and i<b) {
if (a%i==0 and b%i==0) r=i;
i++;
}
cout << "El mcd de " << a << " i " << b << " es " << r << "." << endl;
}
然后按Enter,它显示“非法指令(核心已转储)”。
答案 0 :(得分:-2)
解决方案:
#include <iostream>
using namespace std;
int main () {
int a, b;
cin >> a >> b;
int r=0;
int i=1;
while (i<=a and i<=b) {
if (a%i==0 and b%i==0) r=i;
i++;
}
cout << "El mcd de " << a << " i " << b << " es " << r << "." << endl;
}
我已修复错误,谢谢大家:)