代码如下:
#include <stdio.h>
#include <stdlib.h>
double polynomial(int a[], int i, double x, int n)
{
if (i > 0) return a[n - i] + x * polynomial(a, i - 1, x, n);
else return a[n];
}
int main()
{
int a[99] = { 0 };
int i, n;
double x;
printf("请输入x的值:");
scanf("%lf", &x);
printf("请输入多项式的阶数:");
scanf("%d", &n);
printf("请输入多项式系数");
for (int i = 0; i <= n; i++) {
scanf("%d", &a[i]);
}
printf("多项式的值为:%f", polynomial(a, n, x, n));
return 0;
}