!***************************************************** !* 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(). * !* * !* F90 version by J-P Moreau. * !* (To be linked with polynoms.f90).* !* (www.jpmoreau.fr) * !***************************************************** PROGRAM EVALPOLYNOM USE polynoms type(ar_polynom) p !polynomial type type(ar_number) a,b !double, integer or fractional number print *,'' if (EnterPolynom(' P(X) = ', p).ne.0) then print *,'' call DisplayPolynom(p) else print *,' Error in EnterPolynom()' end if print *,'' print *,'' a%value=1.d0 do while(a%value.ne.0.d0) call ReadNumber(' X = ', a) write (*,10,advance='no') if (EvaluatePolynom(p,a,b).ne.0) then call WriteNumber(b) else print *,' Evaluation failed.' end if print *,'' end do print *,''; print *,'' stop 'Program terminated.' 10 format(' P(X) = ') end ! end of file evalpol.f90