program rozw_xex
  !
  ! rozwiazywanie rownania x=e^-x metoda iteracji
  !
  implicit none
  real x, xs
  real, parameter :: eps = 1.e-5
  integer i

  ! wartosci poczatkowe
  i = 0
  xs = 1.

  ! naglowek tabeli
  write(*,*) "          i      xn"

  do
!     x = exp(-xs)
     x = func(xs)
     i = i + 1
     if ( abs(x-xs) < eps ) exit  ! wyjdz z petli do
     xs = x

     ! drukuj tabele
     write(*,*) i, x

  end do

contains

! uogolnienie; mozemy zamiast exp() probowac inne, zlozone funkcje
  function func(x)
    implicit none
    real, intent(in) :: x
    real func
    func = exp(-x)*cos(x)
    return
  end function func
  
end program rozw_xex


