================================================================

#include <iostream> #define MAX 50 void poly(int n, double a[], const double x0, double p) { int i; p = a[n]; for(i = n-1; i >= 0; i--) { p = a[i] + x0*p; } printf("%lf", p); } int main() { int i,n; double x0,p; double a[MAX+1]; printf("Degree of polynomial: "); scanf("%d",&n); if(n > MAX || n == MAX) { printf("Degree must be less than or equal to 50\n"); do { printf("Degree of polynomial:\n"); scanf("%d", &n); } while (n > MAX || n == MAX); } printf("Coefficients, a[0], a[1], ..., a[%d]\n", n); for(i = 0; i <= n; i++){ scanf("%lf", &a[i]); } printf("value of x = "); scanf("%lf", &x0); poly(n,a,x0,p); }============================================================

this program is about evaluating a polynomial. For example, x^2 + 2x + 1, if x=2, the output would be 9. It won't work on polynomials with a degree higher than 2... there's a problem on the algebraic part... so maybe guys you could figure it out for me... I think there's a problem in this part:

void poly(int n, double a[], const double x0, double p) { int i; p = a[n]; for(i = n-1; i >= 0; i--) { p = a[i] + x0*p; } printf("%lf", p); }

thanks guys and more power!