MST

星途 面试题库

面试题:Fortran中复杂条件判断与数组结合

假设有一个一维数组,存储了一周内每天的最高气温(单位:摄氏度)。编写Fortran程序,使用条件语句判断,如果某天的气温高于30度,输出该天是一周中的第几天以及对应的气温,并统计一周内高温(高于30度)天数。数组元素需在程序内初始化。
43.9万 热度难度
编程语言Fortran

知识考点

AI 面试

面试题答案

一键面试
program high_temperature
    implicit none
    integer :: temperature(7) = [28, 32, 29, 35, 27, 31, 33]
    integer :: i, count_high = 0

    do i = 1, 7
        if (temperature(i) > 30) then
            print *, '第', i, '天的气温为', temperature(i), '度,高于30度'
            count_high = count_high + 1
        end if
    end do

    print *, '一周内高温天数为:', count_high
end program high_temperature