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)<<".";
}
これは、2つの数値の最大公約数を見つけ出し、うまく動作する単純なC++プログラムです。私はwhile(a!=0){
にGCDプログラムのOdd APPCRASHエラー?
int GCD(int a, int b){
while(b!=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) –