作业帮 > 综合 > 作业

fortran函数问题

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/05/26 19:24:21
fortran函数问题
我在函数里面用前面定义的数组时,因为表示方法和函数都一样,都是用小括号,它总以为用的是函数,然后报错,说没定义这个函数,怎么解决这个问题呢?
fortran函数问题
那是因为你没有在函数里面声明那个数组.比如:
program main
integer,dimension(3)::a
integer::s,sum1
s=sum1(a)
end

function sum1(a)
integer,dimension(3)::a ! 必须有这一句
sum1=a(1)+a(2)+a(3)
end function sum1
或者像楼上说的,用module.
module aa
integer,dimension(3)::a
end module aa
program main
use aa
integer::s,sum1
s=sum1(a)
end

function sum1(a)
use aa ! 必须有这一句
sum1=a(1)+a(2)+a(3)
end function sum1