4-2 多项式求值 (15分)
2015-10-13 21:50
204 查看
本题要求实现一个函数,计算阶数为
n,系数为
a[0]...
a的多项式f(x)=∑i=0n(a[i]×xi) 在
x点的值。
函数接口定义:
double f( int n, double a[], double x );其中
n是多项式的阶数,
a[]中存储系数,
x是给定点。函数须返回多项式
f(x)的值。
裁判测试程序样例:
#include <stdio.h>#define MAXN 10double f( int n, double a[], double x );int main(){int n, i;double a[MAXN], x;scanf("%d %lf", &n, &x);for ( i=0; i<=n; i++ )scanf(“%lf”, &a[i]);printf("%.1f\n", f(n, a, x));return 0;}/* 你的代码将被嵌在这里 */
输入样例:
2 1.1 1 2.5 -38.7
输出样例:
-43.1
double f( int n, double a[], double x ){int i;double num=1;double sum=a[0];for(i=1;i<=n;i++){num=num*x;sum=sum+num*a[i];}return sum;}[/code]
相关文章推荐
- hadoop2.6整合hbase 1.1.2完全分布式安装
- 流量控制和拥塞控制
- [POJ 3311]Hie with the Pie——谈论TSP难题DP解决方法
- NYOJ 711 最舒适的路线(并查集+枚举,贪心+欧几里德算法)
- 【LeetCode从零单刷】Spiral Matrix II
- cin、cin.get()、cin.getline()、getline()
- POJ 3268
- LeetCode OJ:Insertion Sort List (插入排序链表)
- ACMJAVA
- SVM-支持向量机算法概述
- UIApplication微解
- python学习-文本数据分析2(文本分类)
- nim IDE aporia的编译
- 【模板】高精度
- poj3259(spfa)
- uvaLive 3713
- 源码解析:3D推拉门式滑动菜单
- Windows命令启动MySQL“ 发生系统错误 5 ”
- 纸上得来终觉浅 绝知此事要躬行
- IOS请求H5页面、要求自定义agent判断是电脑、安卓还是iPhone登录