声明:本博文翻译自https://www.tutorialspoint.com/fortran/fortran_basic_syntax.htm
说明:本博客的所有程序均在intel fortran编译器下执行
fortran程序是由一组程序单元组成的,这些程序单元包括主程序,模块,外部子程序以及过程。
每一个主程序包含一个主程序,可有可无其他程序单元。主程序的语法结构一般如下所示。
Program main
implicit none
!.. type declaration statements
!.. executable statments
End program main
下面写一个简单的fortran程序
Program addNumbers
implicit none
!.. this simple program adds two numbers
real :: a, b, result
a = 12.0
b = 15.0
result = a + b
write(*,'(1x,a,g0)') "the total is ", result
End program addNumbers
执行上面程序,结果如下:
the total is 27.0000000
要点:
1. 所有的fortran程序均已关键字program开始,以end program 结束。program与end program后面可接程序名。比如program main与end program main
2. implicit none语句允许编译器检查所有声明的变量。换言之,该语句使得程序中所有的变量,数组等需要显示声明。
3. write(*,*)与print*均为屏幕显示。想要了解更多的IO操作,需要系统看书。
4. 行缩进可增强代码的可读性。尤其对大多数非计算机专业的学生(我也是一员)或科研人员来说,他们特别不注意排版,代码的可读性实在是太差。要知道,所有事情做到极致,都是艺术!
5. fortran语言对大小写字母不敏感,字符串除外!
fortran中的Identifier、Keywords等知识点这里就不做介绍了。都是很基础的知识,不用细讲。
Fortran:基础语法
最新推荐文章于 2023-02-28 14:17:00 发布