浙大版《C语言程序设计(第3版)》题目集 习题10-4 递归求简单交错幂级数的部分和 (15分)
程序员文章站
2022-03-13 17:09:23
...
#include <stdio.h>
double fn(double x, int n);
int main()
{
double x;
int n;
scanf("%lf %d", &x, &n);
printf("%.2f\n", fn(x, n));
return 0;
}
double fn(double x, int n)
{
if (n == 1 || n == 0)
return x;
else
return x - x * fn(x, n - 1);
}