1: #include <iostream>
2: #include <algorithm>
3:
4: using namespace std;
5:
6: typedef struct
7: {
8: float a;
9: int n;
10: }polynomial;
11: float Calculate(polynomial* coef,int n,float x)
12: {
13: float result=0,temp;
14: int i=0;
15: while(i<n)
16: {
17: temp = coef[i].a;
18: while(coef[i].n>0)
19: {
20: temp *= x;
21: coef[i].n--;
22: }
23: result += temp;
24: i++;
25: }
26: return result;
27: }
28:
29:
30: int main()
31: {
32: polynomial coef[3];
33: coef[0].a=1;
34: coef[0].n=1;
35: coef[1].a=2;
36: coef[1].n=2;
37: coef[2].a=3;
38: coef[2].n=3;
39: float sum=Calculate(coef,3,3);
40: cout<<"sum="<<sum;
41: return 0;
42: }