      include 'horner.f'

      PROGRAM NEWTON1
c     pierwiastki rzeczywiste wielomianu rzrczywistego
      implicit none
      real*8 a,b,c,R,S,xs,xn,x0,eps
      integer j,k,pyt,N,p,pmax
      dimension a(0:100),b(0:100),c(0:100)
   10 write(*,*)'PROGRAM NEWTON1'
      write(*,*)'PODAJ STOPIEN WIELOMIANU N'
      read (*,*) N
      write(*,*)'PODAWAJ WSPOLCZYNNIKI: a(j) j=0,1,...,N'
      do 1,j=0,N,1
      read (*,*)a(j)
    1 continue
      write(*,*)'PODAJ x0'
      read (*,*)x0
      write(*,*)'PODAJ eps,pmax'
      read (*,*)eps,pmax
      xs=x0
      do 2,p=0,pmax,1
      call horner(N,a,b,xs,R)
      call horner(N-1,b,c,xs,S)
      xn=xs-R/S
      if(abs(xn-xs).le.eps)then
      goto 20
      else
      xs=xn
      endif 
    2 continue
   20 write(*,*)'GOTOWE'
      write(*,*)'<ENTER>'
      read (*,*)
      write(*,*)'p=',p
      write(*,*)'xn=',xn
      write(*,*)'eps=',eps
      write(*,*)' 0 - KONIEC'
      write(*,*)' 1 - OD POCZATKU'
      read (*,*)pyt
      if(pyt.eq.0)goto 100
      goto 10
  100 stop 100
      end

          
