1
using namespace std;
#include <iostream>
int GCD(int a, int b){
while(b!=0){
int temp=b;
b=a%b;
a=temp;
}
return a;
}
int main(){
int a=0, b=0;
cout<<"Please enter two integers to find their GCD using the Euclidean algorithm.";
cin>>a>>b;
cout<<"The greatest common divisor of "<<a<<" and "<<b<<" is "<<GCD(a,b)<<".";
}
这是一个简单的C++程序,它可以找到两个数字的最大公约数,它运行得很好。但是,如果我改变GCD程序中奇怪的APPCRASH错误?
int GCD(int a, int b){
while(b!=0){
为while(a!=0){
,我遇到一个错误APPCRASH,异常代码c0000094杀死我跑。我正在运行C++ 11 ISO标准,而我的IDE是Code :: Blocks 16.
*我遇到APPCRASH错误*输入什么?可能是什么时候?b = 0? –
@MichaelWalz如果'b = 0'怎么办? –
@GauravSehgal对不起,我使用了100和150,150和150,以及150和100.这是一个入门级C++课程的简单任务,所以我忽略了异常(以及多么不专业的:P) –