MST

星途 面试题库

面试题:Fortran在金融工程利率计算中的应用

假设在金融工程中,要计算复利。已知初始本金为P,年利率为r,存款年限为n,使用Fortran编写一个程序来计算最终的本息和。要求程序结构清晰,使用合适的变量类型和循环结构。
46.3万 热度难度
编程语言Fortran

知识考点

AI 面试

面试题答案

一键面试
program compound_interest
    implicit none
    real :: P, r, amount
    integer :: n, i

   ! 输入初始本金、年利率和存款年限
    write(*,*) '请输入初始本金:'
    read(*,*) P
    write(*,*) '请输入年利率 (例如 0.05 表示 5%):'
    read(*,*) r
    write(*,*) '请输入存款年限:'
    read(*,*) n

    amount = P
    do i = 1, n
        amount = amount * (1 + r)
    end do

    write(*,*) '最终的本息和为:', amount
end program compound_interest