#include<stdio.h>
#include<math.h>
int main(void){
double a=0,r=0,n=0;
printf("Enter Constant a:");
scanf("%lf",&a);
printf("Enter Constant r:");
scanf("%lf",&r);
printf("Enter Variable n:");
scanf("%lf",&n);
double an;
an = geom_rec(a,r,n); // Line 15
return 0;
}
double geom_rec(double a,double r,double n){ // Line 20
double ans=a;
return a;
}
错误:
Line 20: error: conflicting types for 'geom_rec'
Line 15: error: previous implicit declaration of 'geom_rec' was here
最佳答案
您忘记为函数创建原型(prototype)。
将以下内容放在 main
函数之前(您也可以将整个函数移到 main
之上):
double geom_rec(double a,double r,double n);
如果您调用之前未定义或原型(prototype)化的函数,编译器会假定它返回 int
- 这与您的实际返回类型冲突。
关于c - 两个 double 怎么会是相互冲突的类型呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212378/