MST

星途 面试题库

面试题:Fortran条件语句的高级嵌套应用

编写一个Fortran程序,从键盘输入三个整数a、b、c。使用嵌套的条件语句,找出这三个数中的最大值,并输出。要求使用IF - THEN - ELSEIF - ELSE结构实现。
46.1万 热度难度
编程语言Fortran

知识考点

AI 面试

面试题答案

一键面试
program find_max
    implicit none
    integer :: a, b, c, max_value

   ! 从键盘读取三个整数
    write(*,*) '请输入三个整数:'
    read(*,*) a, b, c

   ! 找出最大值
    if (a >= b) then
        if (a >= c) then
            max_value = a
        else
            max_value = c
        end if
    else
        if (b >= c) then
            max_value = b
        else
            max_value = c
        end if
    end if

   ! 输出最大值
    write(*,*) '这三个数中的最大值是:', max_value
end program find_max