#include#include #define MAXSIZE 1024double polynomial[MAXSIZE];double SumPolynomial(int ini, double polynomial[], double x);int main(){ memset(polynomial, 0, sizeof(polynomial)); printf("Please input your polynomial:\n"); double coefficient; int exponential; double x; int max=0; int cnt=0; while(1) { //printf("test!\n"); scanf("%lf %d", &coefficient, &exponential); //++cnt; if((exponential!=0)||(coefficient!=0.0))//The "&&" is wrong,while the "||" is right. { polynomial[exponential]=coefficient; if(exponential>max) max=exponential; //printf("%d: %lf %d\n", cnt, coefficient, exponential); } else break; } printf("Please input the values of x:\n"); scanf("%lf", &x); //printf("The value of max is equal to %d.\n", max); /*for(i=max; i>=0; --i) { printf("|%d:%f|", i, polynomial[i]); if(i!=0) printf(","); else printf("."); }*/ //printf("\n"); double sum; sum=SumPolynomial(max, polynomial, x); printf("f(%f)=", x); int i; for(i=max; i>=0; --i) { if(polynomial[i]!=0) { if(i!=max) printf("+"); printf("%f*%f^%d", polynomial[i], x, i); } } printf("=%f.\n",sum); return 0;}double SumPolynomial(int ini, double polynomial[], double x){ double sum=polynomial[ini]; int i; for(i=ini-1; i>=0; --i) { //printf("exponential=%d:sum=%f,polynomial[%d]=%f\n", i, sum); sum=sum*x+polynomial[i];// "i" is right, "ini" is wrong! //printf("exponential=%d:sum=%f\n", i, sum); } //???:check "sum". return sum;}