/**************************************************** * This program evaluates a polynomial P(x) at x * * ------------------------------------------------- * * Ref.: "Mathématiques en Turbo-Pascal By M. Ducamp * * and A. Reverchon (vol 2), Eyrolles, Paris, 1988" * * [BIBLI 05]. * * ------------------------------------------------- * * SAMPLE RUN: * * * * EVALUATION OF A POLYNOMIAL P(X) FOR X GIVEN: * * * * P(X) = x3 - 5x2 + 7x + 4 * * * * + X3 - 5 X2 + 7 X + 4 * * * * X = 1 * * P(X) = + 7 * * X = 10 * * P(X) = + 574 * * X = -5/2 * * P(X) = - 483/8 * * X = 1/3 * * P(X) = + 157/27 * * X = 0 * * P(X) = + 4 * * * * ------------------------------------------------- * * Functions used (of module Polynoms): * * * * EnterPolynom(), DisplayPolynom(), ReadNumber(), * * EvaluatePolynom() and WriteNumber(). * * * * C++ version by J-P Moreau. * * (To be linked with polynoms.cpp).* * (www.jpmoreau.fr) * ****************************************************/ #include #include #include "polynoms.h" ar_polynom *p; // polynomial type ar_number a,b; // double, integer or fractional type void main() { //dynamic memory allocation of polynomial p = (ar_polynom *) calloc(1,sizeof(ar_polynom)); printf("\n"); if (EnterPolynom(" P(X) = ", p)) { printf("\n"); DisplayPolynom(p); printf("\n\n"); } else printf(" Error in EnterPolynom().\n\n"); do { ReadNumber("X = ", &a); printf(" P(X) = "); if (EvaluatePolynom(p,&a,&b)) WriteNumber(b); else printf(" Evaluation failed."); printf("\n"); } while (a.value!=0); printf("\n\n"); free(p); } // end of file evalpol.cpp