【发布时间】:2018-05-09 00:44:33
【问题描述】:
在这种情况下,如何获得双差异的绝对值?
double cos_delta(double x, double delta)
{
int n = 1; // n should start with 1 because it is the number of terms
double diff = cos_N(x, n ) - cos_N(x, n - 1); // n and n-1 instead of n-1 and n-2
********* here ************
while (diff > delta) { // fabs returns absolute value of a double
n++;
diff = cos_N(x, n ) - cos_N(x, n - 1);
}
printf("n = %d\n", n);
return cos_N(x, n);
}
【问题讨论】:
-
为什么不用
math.h? -
因为我无法在这个程序中使用它
-
这不是问题,这里太容易回答了:
double abs(double i) { return i < 0? -i: i; } -
但在 C 中,据我所知,您不能在函数中使用派系!我知道这些问题对你们来说很容易,但我正在努力学习
-
嗯? “不能在函数中使用派系”是什么意思?这与您的问题有什么关系?
标签: c math double absolute arithmetic-expressions