为什么这个程序不起作用?这是使用递归函数的简单最大公约数程序。它编译没有错误,但是当我运行 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);
}