      PROGRAM HOR2
c     OBLICZA WARTOSC WIELOMIANU I JEGO POCHODNEJ W x
c     POSLUGUJE SIE PODPROGRAMEM horner.f DOLACZONYM
      implicit none
      integer N,j,k,pyt
      real*8 a,b,c,x,R,S
      dimension a(0:100),b(0:100),c(0:100)
   10 write(*,*)'PROGEAM HOR2'
      write(*,*)'PODAJ N - STOPIEN, 0<N<101'
      read (*,*) N
      write(*,*)'PODAWAJ a(j), j=0,1,...,N'
      do 1,j=0,N,1
      read(*,*) a(j)
    1 continue
      write(*,*)'PODAJ x'
      read (*,*) x
      call horner(N,a,b,x,R)
      call horner(N-1,b,c,x,S)
      write(*,*)'GOTOWE'
      write(*,*)'<ENTER>'
      read (*,*)
      write(*,*)' W(x)=',R
      write(*,*)'W*(x)=',S
      write(*,*)' 0 - KONIEC'
      write(*,*)' 1 - OD POCZATKU'
      read (*,*) pyt
      if(pyt.eq.0)goto100
      goto 10
  100 stop 100
      end
       
      subroutine horner(N,a,b,x,R)
      implicit none
      real*8 a,b,R,x
      integer N,j
      dimension a(0:N),b(0:N-1)
      b(N-1)=a(N)
      do 1,j=N-2,0,-1
      b(j)=a(j+1)+x*b(j+1)
    1 continue
      R=a(0)+x*b(0)
      return
      end
