このプログラムが機能しないのはなぜですか? これは、再帰関数を使用した単純な最大公約数プログラムです。エラーなしでコンパイルされますが、program.exe を実行すると単にクラッシュします:「プログラムは動作を停止しました」。コードブロックと Notepad++ で試しました。gccコンパイラを使用しています。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int gcd(int,int);
int main(int argc,const char* argv[]){
int a;
int b;
a = atoi(argv[1]);
b = atoi(argv[2]);
printf("The greatest common divisor of %d and %d is %d\n",a,b,gcd(a,b));
return 0;
}
int gcd(int a,int b){
if(a==0)
return a;
else
return gcd(b, a%b);
}