当前位置:网站首页>请用递归的方法计算下列函数的值:px(x,n)=x-x^2 +x^3- x^4+… ((-1)n-1)(xn) n>0 **输入格式要求:“%lf%d“ 提示信息:“Enter X and N:”

请用递归的方法计算下列函数的值:px(x,n)=x-x^2 +x^3- x^4+… ((-1)n-1)(xn) n>0 **输入格式要求:“%lf%d“ 提示信息:“Enter X and N:”

2022-06-12 04:16:00 Kilmil

#include <stdio.h>
#include <math.h>
int m = 0, n1 = 0;
int px(double x, int n, int *s);

int main(void) {
	double x = 0;
	int n = 0, s = 0;
	printf("Enter X and N:");
	scanf("%lf%d", &x, &n);
	n1 = n - 1;
	px(x, n, &s);
	printf("%d", s);
	return 0;
}

int px(double x, int n, int *p) {
	if (m <= n1) {
		*p += px(x, ++m, p);
	}
	return pow(-1, n - 1) * pow(x, (double)n);
}
原网站

版权声明
本文为[Kilmil]所创,转载请带上原文链接,感谢
https://blog.csdn.net/killer_milk/article/details/125136978