contents

2.5 part 4

code を Fortran で書く。

code


! 2.5.f90
! 2023-01-14
!
! r,  rate
! n,  nunber of years
! cf, cash flow stream
! pv, present value
  
program ex2_5
implicit none
integer n
real    cf(20)
integer  i(20)
real     r
  
! input
n = 20
r = 0.1e0
i = (/0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19/)
cf(1:n) = 500.0e3

! output
print *, '2.5.f90'
print '(a5, i5)',  'n= ', n
print '(a5,f5.3)', 'r= ', r
print '(a5,20i3)', 'i= ', i
print '(a5,20i7)', 'cf= ', int(cf(:))
print '(a5,i10)',  'pv= ', int(pv(cf,r,i))
  
contains
function pv(cf, r, i)
    implicit none
    real pv
    real cf(:)
    real r
    integer i(:)
    pv = sum(cf / (1 + r) ** i)
end function pv
end program ex2_5
! eof

output

2.5.f90
n=    20
r= 0.100
i=   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
cf=  500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000
pv=    4682459

history

2023-01-14 create.