在 CentOS 上学习 Fortran,一般分三步:安装编译器 → 写第一个程序 → 系统学习语法与工具。下面给你一套实用路线。
sudo yum install gcc-gfortran
安装完成后检查:
gfortran --version
mkdir fortran_learn
cd fortran_learn
vi hello.f90
program hello
implicit none
print *, "Hello, Fortran!"
end program hello
gfortran hello.f90 -o hello
./hello
输出:
Hello, Fortran!
program / end program)integer, real, character, logical)implicit none 的重要性read *, print *,if / elsedo 循环select casesum, maxval 等)subroutine add(a,b,c)
real :: a,b,c
c = a + b
end subroutine
open(unit=10, file='data.txt')
read(10,*) x
close(10)
✅ 从 Fortran 90/95 开始,不要学太老的 Fortran 77
✅ 多写数值计算小程序(如求和、积分)
✅ 结合 Linux 命令行使用
如果你愿意,我可以:
你学 Fortran 主要用于什么方向?