#include <stdio.h>
#include <math.h>
double fact(int n) {
if (n == 0)
return 1;
return fact(n - 1 * n);
}
int main() {
double x, y = 0, c = 1, b = 1.0;
int n = 1, t = 1;
printf("x的值:");
scanf("%lf", &x);
while (b >= pow(10, -6)) {
c = pow(x, 2 * n - 1) / fact(2 * n - 1);
y += t * b;
t = -t;
n++;
b = c;
}
printf("%if", y);
printf("%d", n - 1);
return 0;
}
return fact(n - 1 * n);这是啥意思?n-1 * n不就是0了吗?
是return n * fact(n - 1);吧
第7行应该是:
return fact(n - 1)* n;