时间限制: 400ms内存限制: 64MB代码长度限制: 16KB
double f( int n, double a[], double x );
其中n
是多项式的阶数,a[]
中存储系数,x
是给定点。函数须返回多项式f(x)
的值。c++
1 #include <stdio.h> 2 #define MAXN 10 3 double f( int n, double a[], double x ); 4 int main() 5 { 6 int n, i; 7 double a[MAXN], x; 8 scanf("%d %lf", &n, &x); 9 for ( i=0; i<=n; i++ ) 10 scanf(“%lf”, &a[i]); 11 printf("%.1f\n", f(n, a, x)); 12 return 0; 13 } 14 /* 你的代码将被嵌在这里 */
2 1.1
函数
1 2.5 -38.7
测试
-43.1
spa
1 double f( int n, double a[], double x ) 2 { 3 int i=0,j=0; 4 double sum=0,x_n=1;; 5 for(i=0;i<=n;i++) 6 { 7 sum += a[i] * x_n; 8 x_n *= x; 9 } 10 return sum; 11 }
做者:耑新新,发布于 博客园code
转载请注明出处,欢迎邮件交流:zhuanxinxin@foxmail.comblog