泰勒级数展开如何解决我的代码?与给定的精度COS(X)的
EPS 递归方法
[错误]重载函数没有上下文类型的信息
如何能我修复这个错误?
#include <stdio.h>
#include <math.h>
double cos(double x, double eps, double s=0,double n=0,double a=0) {
if (abs(n)<1){
cos=cos(x, eps,1,1,1);
}
else {
a = -a*x*x/((2*n-1) * (2*n));
if (abs(a)<=eps) {
cos=s;
}
else{
cos=cos(x, eps, s+a, a,n+1);
}
}
}
int main() {
double x;
scanf("%f", &x);
cos(x, 0.000000000000001);
}
函数'cos'被声明为返回一个double值。但是,我没有看到该函数中的任何'return'语句。 – abelenky
另外C不支持默认参数 – Kevin
梅,C不是pascal!使用'return s;'而不是'cos = s;'等等。 – HolyBlackCat