こんにちは、stackoverflowコミュニティ!私は自分のコードにいくつか問題があります。私は現在学生ですので、基本的に私は初心者です。ユークリッドアルゴリズムを使用すると、下に示すコードは、商が0に達するまで2つの数値を除算し、除算する必要がありますが、商が0になる直前の最後の分割プロセスで停止します。プログラムがこのためにクラッシュするかどうかはわかりません。皆さんからの初心者にやさしい返信をお待ちしています。ありがとう!プログラムのクラッシュとコーディングにおける算術演算に関する質問
int quotient,quotient2,remainder,remainder2,x,y;
int foo()
{
printf("Enter a number: ");
scanf("%d", &x);
printf("Enter another number: ");
scanf("%d", &y);
if(y >= x){
quotient2 = y/x;
remainder2 = y % x;
printf("%d = %d(%d) + %d\n", y,x,quotient2,remainder2);
if(quotient2 != 0){
do{
y = x;
x = remainder2;
quotient2 = y/x;
remainder2 = y % x;
printf("%d = %d(%d) + %d\n", y,x,quotient2,remainder2);
} while(quotient2 != 0);
}
} else if(x > y){
quotient = x/y;
remainder = x % y;
printf("%d = %d(%d) + %d\n", x,y,quotient,remainder);
if(quotient != 0){
do{
x = y;
y = remainder;
quotient = x/y;
remainder = x % y;
printf("%d = %d(%d) + %d\n", x,y,quotient,remainder);
} while(quotient != 0);
}
}
system("pause");
return 0;
}
CとC++ 2つの異なる言語である - いずれかを選択 – PaulMcKenzie
。あなたのコードをデバッグしようとしましたか? – wimh
'do ... while'ループで、' remainder = x%y; 'の結果が0ならば、次の繰り返しでゼロ除算 –