在 Ubuntu 上学习 Fortran,一般分三步:安装编译器 → 写第一个程序 → 学习资源和练习。下面给你一份比较实用的入门指南。
Ubuntu 上最常用的是 gfortran(GNU Fortran)。
sudo apt update
sudo apt install gfortran
安装完成后检查版本:
gfortran --version
能看到版本号就说明安装成功。
mkdir fortran_study
cd fortran_study
nano 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)do)if)subroutine)和函数(function)program sum_example
implicit none
integer :: i, s
s = 0
do i = 1, 100
s = s + i
end do
print *, "1 到 100 的和是:", s
end program sum_example
nano / vim安装 VS Code:
sudo snap install code --classic
module)如果你愿意,我可以:
你学 Fortran 主要是出于 科研 / 工程 / 课程作业 哪方面?