c   4.$B<+A3BP?t$NDl(B
c     $B?9@n(B $BLwBg(B  , 22980138
c      
      program ex4
c
      implicit none      
      integer :: i
      integer(8) :: fact
      real(4) :: ee(30),eea(30),eer(30)
      real(8) :: ed(30),eda(30),edr(30),d

c-----$B<+A3BP?t$NDl$N??CM(B
      d=dexp(1.0d0)
      write(6,300) d

       ee(1)=1.0e0
       ed(1)=1.0d0
       do i=2,30
c---------$B<+A3BP?t$NCM(B
c-------------(dble $B$OG\@:EY<B?t2=$N5-9f(B)
          ee(i)=ee(i-1)+1.0e0/float(fact(i-1))
          ed(i)=ed(i-1)+1.0d0/dble(fact(i-1))
c---------$B@dBP8m:9(B          
          eea(i)=abs(d-ee(i))
          eda(i)=abs(d-ed(i))
c---------$BAjBP8m:9(B       
          eer(i)=eea(i)/real(d)
          edr(i)=eda(i)/d
       enddo

c------$B0lO"$N%G!<%?$N=PNO(B    
       write(6,*) ''
       write(6,*) '$B<+A3BP?t$NCM(B e'
       write(6,200)
       do i=2,30
          write(6,100) i , ee(i) , ed(i)
       enddo

       write(6,*) ''
       write(6,*) '$B@dBP8m:9(B |e-d|'
       write(6,200)       
       do i=2,30
          write(6,100) i,eea(i),eda(i)
       enddo
     
       write(6,*) ''
       write(6,*) '$BAjBP8m:9(B |e-d|/d'
       write(6,200)
       do i=2,30
          write(6,100) i,eer(i),edr(i)
       enddo 
      stop
  100 format(2x,i3,e18.9,d26.18)
  200 format(1x,'$B9`$N?t(B',1x,'$BC1@:EY(B',11x,'$BG\@:EY(B') 
  300 format(1x,'$B<+A3BP?t$NDl$N??CM(B d=',d26.18) 
      end

c-----$B3,>h$N4X?t(B
      function fact(x)
       implicit none
       integer(4) :: j
       integer(8) :: fact
       integer,intent(in) :: x
       fact=1
        do j=1,x
           fact=fact*j
        enddo
      return
      end
