! 2.6.f90 ! 20140211 1.1 ! $Id: 2.6.f90 1.2 2016/10/29 02:10:54 s Exp $ ! ! cf : cash flow ! pv : preset value ! r : rate ! ! main ! implicit none integer j, k, n1, n2, n3, n4 real(8) pv1, pv2, pv3, pv4, r integer, dimension(0:100) :: i real(8), dimension(0:100) :: cf1, cf2, cf3, cf4 ! input r = 0.12 i(0:100) = (/(k, k=0, 100)/) n1 = 6 - 1 cf1(0:n1) = -1000.0 n2 = 6 - 1 cf2(0) = -1000.0 - 900.0 cf2(1:n2) = -900.0 n3 = 12 - 1 cf3(0:n3) = -1000.0 n4 = 12 - 1 cf4(0) = -1000.0 - 900.0 cf4(1:n4) = -900.0 ! calculate pv1 = sum(cf1(0:n1) / (1.0 + r / 12.0) ** i(0:n1) ) pv2 = sum(cf2(0:n2) / (1.0 + r / 12.0) ** i(0:n2)) pv3 = sum(cf3(0:n3) / (1.0 + r / 12.0) ** i(0:n3)) pv4 = sum(cf4(0:n4) / (1.0 + r / 12.0) ** i(0:n4)) ! output print *, '2.6' print *, 'input' print '(a5, f10.2)', 'r=', r print '(a5, 12i7)', 'i=', (i(j), j = 0, 11) print '(a5,(12f7.0))', 'cf1= ', (cf1(j), j = 0, n1) print '(a5,(12f7.0))', 'cf2= ', (cf2(j), j = 0, n2) print '(a5,(12f7.0))', 'cf3= ', (cf3(j), j = 0, n3) print '(a5,(12f7.0))', 'cf4= ', (cf4(j), j = 0, n4) print *, 'output' print '(a10, i10)', 'pv1($) = ', int(pv1) print '(a10, i10)', 'pv2($) = ', int(pv2) print '(a10, i10)', 'pv3($) = ', int(pv3) print '(a10, i10)', 'pv4($) = ', int(pv4) stop end ! end of 2.6.f90 ! ! below is output ! !2.6 ! input ! r= 0.12 ! i= 0 1 2 3 4 5 6 7 8 9 10 11 !cf1= -1000. -1000. -1000. -1000. -1000. -1000. !cf2= -1900. -900. -900. -900. -900. -900. !cf3= -1000. -1000. -1000. -1000. -1000. -1000. -1000. -1000. -1000. -1000. -1000. -1000. !cf4= -1900. -900. -900. -900. -900. -900. -900. -900. -900. -900. -900. -900. ! output ! pv1($) = -5853 ! pv2($) = -6268 ! pv3($) = -11367 ! pv4($) = -11230