fortran severe 161 数组超界问题,program shuzhichuanreimplicit noneinteger n,ireal,allocatable::a(:),b(:),c(:),d(:),g(:),q(:),o(:)allocate(a(n),b(n),c(n),d(n),g(n),q(n),o(n))write(*,*)'请输入控制体个数n:'read(*,*) nwrite(*,*)'请输入

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 22:20:36
fortransevere161数组超界问题,programshuzhichuanreimplicitnoneintegern,ireal,allocatable::a(:),b(:),c(:),d(

fortran severe 161 数组超界问题,program shuzhichuanreimplicit noneinteger n,ireal,allocatable::a(:),b(:),c(:),d(:),g(:),q(:),o(:)allocate(a(n),b(n),c(n),d(n),g(n),q(n),o(n))write(*,*)'请输入控制体个数n:'read(*,*) nwrite(*,*)'请输入
fortran severe 161 数组超界问题,
program shuzhichuanre
implicit none
integer n,i
real,allocatable::a(:),b(:),c(:),d(:),g(:),q(:),o(:)
allocate(a(n),b(n),c(n),d(n),g(n),q(n),o(n))
write(*,*)'请输入控制体个数n:'
read(*,*) n
write(*,*)'请输入已知边界o(0)的值:'
read(*,*) o(0)
write(*,*)'请输入已知边界o(n)的值:'
read(*,*) o(n)
do i=1,n-1
a(i)=n**2-2*n
b(i)=2*n**2+32
c(i)=n**2+2*n
d(i)=0
enddo
d(1)=d(1)+a(1)*o(0)
g(1)=c(1)/b(1)
q(1)=d(1)/b(1)
do i=2,n-1
g(i)=c(i)/(b(i)-a(i)*g(i-1))
q(i)=(d(i)+a(i)*q(i-1))/(b(i)-a(i)*g(i-1))
enddo
10 o(n-1)=g(n-1)*o(n)+q(n-1)
n=n-1
\x09if(n>1) then
\x09goto 10
\x09endif
write(*,*) o
end

fortran severe 161 数组超界问题,program shuzhichuanreimplicit noneinteger n,ireal,allocatable::a(:),b(:),c(:),d(:),g(:),q(:),o(:)allocate(a(n),b(n),c(n),d(n),g(n),q(n),o(n))write(*,*)'请输入控制体个数n:'read(*,*) nwrite(*,*)'请输入
allocate(a(n),b(n),c(n),d(n),g(n),q(n),o(n))
这一句要放到read(*,*) n 之后
还有一个错误,fortran的数组是从1开始的,当你改正上面的错误了之后,接下来会抱错关于o(0)的问题,所以建议修改.