主题:运行结果不对
program main
implicit none
integer:: n = 10
real:: y
!print *, 'enter the number n:'
!read(unit = *, fmt = *), n
call sun(n, y)
write(unit = *, fmt = *), 'y =', y
end program main
subroutine sun(n, s)
! 子例程序
implicit none
integer:: i, n
real:: s, t
s = 0.0
do i = 1, n
t = 1/i
s = s+t
enddo
print *, 's =', s, 'n =', n
end subroutine
运行结果不对,运行后,s=1.00000,n=10,y=1.0000.
不知原因是什么?求指教
implicit none
integer:: n = 10
real:: y
!print *, 'enter the number n:'
!read(unit = *, fmt = *), n
call sun(n, y)
write(unit = *, fmt = *), 'y =', y
end program main
subroutine sun(n, s)
! 子例程序
implicit none
integer:: i, n
real:: s, t
s = 0.0
do i = 1, n
t = 1/i
s = s+t
enddo
print *, 's =', s, 'n =', n
end subroutine
运行结果不对,运行后,s=1.00000,n=10,y=1.0000.
不知原因是什么?求指教