fortran 中定义内部函数

 

001、

[root@localhost test]# cat test01.f90
program test01_fortran

        implicit none

        real :: a

        print *, "Please input an real number: "
        read *, a

        print *, test01_fun(a)

contains                     ## 声明内部使用的函数

        real function test01_fun(x)             ## 定义函implicit none

                real :: x

                test01_fun = x * x              ## 函数返回值是函数名本身
        end function test01_fun

end program test01_fortran
[root@localhost test]# gfortran test01.f90 -Wall -O2 -o kkk
[root@localhost test]# ls
kkk  test01.f90
[root@localhost test]# ./kkk
 Please input an real number:
5
   25.0000000

 

image

 。

 

posted @ 2026-07-21 09:57  小鲨鱼2018  阅读(6)  评论(0)    收藏  举报