手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

windows平台下fortran编程使用函数function

时间:2024-10-16 18:14:13

1、关于codeblocks IDE的极速安装请参考百度经验<<Windows下极速搭建fortran开发环境>>

windows平台下fortran编程使用函数function

2、函数的一般形式:类型 function xxxx(参数1,参数2.....) implicit none 参数1类型 参数2类型 xxxxxx代码endfunctionxxxx

3、编写函数传入2个参数其中一个是字符串另一个是整数循环整数次,打印字符串函数结束时改变传入的整数值传入的参数有如下三种形式: intent(in):在子程序中不可改变值 intent(out):可在子程序中改变 intent(inout):可在子程序中改变===================================== !函数 integer function dy2003310(strFileName, times) implicit none character(*),intent(in)::strFileName integer,intent(in)::times integer::i do i=1,times print *, strFileName end do dy2003310=times+times end function dy2003310

4、使用fortran的关键字containscontains是Fortran 90中新增的一个语法功能在module或者subroutine中可以用contains来包含其他的module或者subroutine

windows平台下fortran编程使用函数function

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 *, "*****************************************"

windows平台下fortran编程使用函数function

6、在codeblocks中编译、链接:

windows平台下fortran编程使用函数function

7、运行、测试结果如下可以看到:函数调用前参数2等于4调用后函数返回一个值8并将其赋给了参数2

windows平台下fortran编程使用函数function
© 手抄报圈