Metcalf、Reid、および Cohen による「現代の Fortran の説明」に取り組んでいます。第 4 章では、宿題としてフィボナッチ プログラムを割り当てています。以下の私のコードはコンパイルされません。どうすれば修正できますか?
! Fibonacci here we go
integer :: lim, i
lim=0
read *, lim
integer, dimension(lim) :: fib
if( lim >= 1 )
fib(1) = 0
end if
if( lim >= 2 )
fib(2) = 1
end if
if( lim >= 3 )
fib(3) = 1
end if
do i=4, lim
fib(i) = fib(i-2) + fib(i-1)
end do
do i=1, size(fib)
print *, fib(i)
end do
end
また、ここに私が得ているエラーがあります。これを必要なものに短縮しようとしますが、Fortran エラー ログを見るときに何が必要かわかりません。
Compiling the source code....
$/usr/bin/gfortran /tmp/135997827718658.f95 -o /tmp/135997827718658 2>&1
In file /tmp/135997827718658.f95:7
integer, dimension(lim) :: fib
1
Error: Unexpected data declaration statement at (1)
In file /tmp/135997827718658.f95:9
if( lim >= 1 )
1
Error: Unclassifiable statement in IF-clause at (1)
In file /tmp/135997827718658.f95:10
fib(1) = 0
1
Error: Unclassifiable statement at (1)
In file /tmp/135997827718658.f95:11
end if
1
Error: Expecting END PROGRAM statement at (1)
In file /tmp/135997827718658.f95:13
if( lim >= 2 )
1
Error: Unclassifiable statement in IF-clause at (1)
In file /tmp/135997827718658.f95:14
fib(2) = 1
1
Error: Unclassifiable statement at (1)
In file /tmp/135997827718658.f95:15
end if
1
Error: Expecting END PROGRAM statement at (1)
In file /tmp/135997827718658.f95:17
if( lim >= 3 )
1
Error: Unclassifiable statement in IF-clause at (1)
In file /tmp/135997827718658.f95:18
fib(3) = 1
1
Error: Unclassifiable statement at (1)
In file /tmp/135997827718658.f95:19
end if
1
Error: Expecting END PROGRAM statement at (1)
In file /tmp/135997827718658.f95:22
fib(i) = fib(i-2) + fib(i-1)
1
Error: Statement function at (1) is recursive
Error: Unexpected end of file in '/tmp/135997827718658.f95'