- #1
Sue Parks
- 38
- 0
I have a program that calculates the Fibonacci numbers from 1 to 100. The program runs fine. I am not sure how to take my output and display them in an ARRAY. Any ideas?
I tired to pass the array variable through the equation, but my output was weird. I would have 1, 1, 3347... Basically, I would get the first two values, and then once the program entered my do loop, I would get very high integer values . I tried to use a DO loop at the end of the program, but I was unsuccessful.
EXAMPLE:
Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2)
I tired to pass the array variable through the equation, but my output was weird. I would have 1, 1, 3347... Basically, I would get the first two values, and then once the program entered my do loop, I would get very high integer values . I tried to use a DO loop at the end of the program, but I was unsuccessful.
EXAMPLE:
Fibonacci(i) = Fibonacci(i-1) + Fibonacci(i-2)
Fortran:
Program large_integers
IMPLICIT NONE
Integer , PARAMETER :: M = 100
Integer, DIMENSION (M) ::FIBONACCI
integer, parameter :: IK = selected_real_kind(25)
Integer (IK) :: fn, f2, f1
INTEGER :: n, I
!allocate (FIBONACCI(fn))
! OPEN(14, FILE = "MY_FIBONACCI.out", ACTION = "WRITE", STATUS = "unknown")
f1 = 1
f2 = 1
IF (m >= 1) THEN
PRINT *, f2
END IF
IF (m >= 2) THEN
PRINT *, f1
END IF
DO n=4,m
fn = f1 + f2
PRINT *, fn
f2 = f1
f1 = fn
END DO
!DO i = 1, m
!write (14,*) FIBONACCI(fn)
!END do
CLOSE(14)
END Program large_integers
[ / code ]