fortran试用递归函数计算等差数列1 2 3 ... 99 100的值
展开全部
module module1
real(4):: n
contains
recursive subroutine sub1(x,y)
real(4),intent(inout):: x
if (x < n) then
x = x + 1
y=y+x
call sub1(x,y)
end if
end subroutine sub1
end module module1
program main
use module1
real(4):: x = 0,y=0
print *, 'Enter number of repeats'
n=100
call sub1(x,y)
write(*,*)y
end program main
希望能够帮到你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询