fortran编程使用子程序function使代码能够重复调用并使用函数的返回值
工具/原料
codeblocks IDE编程环境
方法/步骤
2
函数的一般形式:类型 function xxxx(参数1,参数2.....) implicit none 参数1类型 参数2类型 xxxxxx代码end function xxxx
4
使用fortran的关键字containscontains是Fortran 90中新增的一个语法功能在module或者subroutine中可以用contains来包含其他的module或者subroutine
5
编写主程序测试函数的返回值:======================================== implicit none character(len=255)::str integer::n str='168' n=4 print *, '*****************************************' print *, '函数运行之前,n=',n n=dy2003310(str,n) print *, '函数运行之后,n=',n print *, '*****************************************'
6
在codeblocks中编译、链接:
7
运行、测试结果如下可以看到:函数调用前参数2等于4调用后函数返回一个值8并将其赋给了参数2
上一篇:如何快速剪切视频
下一篇:GRE写作之如何写得新颖