I am using fortran 90 to find the prime numbers (1-100). When I print to the console, everything works. If I try to write to an text file (.out).(adsbygoogle = window.adsbygoogle || []).push({});

This is from my command line:

Sues-MacBook-Air:FORTRAN sueparks$ gfortran PRIME.f90

Sues-MacBook-Air:FORTRAN sueparks$ ./MY_PRIME.out

Code (Fortran):

PROGRAM PRIME

implicitnone

integer, PARAMETER::M=100

integer::at, found, i

logical::is_prime

integer, dimension(M)::primes! array that will hold the primes

open (1, file="MY_PRIME.out", status="unknown")

!print *, "How many primes would you like to find?"

!read *, num_primes

primes(1)=2

at =2

found =1

do

is_prime =.true.! assume prime

do i =1, found

if(modulo(at, primes(i))==0)then! if divisible by any other element

is_prime =.false.! in the array, then not prime.

exit

endif

enddo

if(is_prime)then

found = found +1

primes(found)= at

print *, at

WRITE(1,*)"THE FIRST 100 PRIME NUMBERS:" ,AT

CLOSE(1)

endif

at = at +1

if(found == M)then! stop when all primes are found

exit

endif

enddo

ENDPROGRAM PRIME

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Fortran (90) runtime error: End of file

Loading...

Similar Threads - Fortran runtime error | Date |
---|---|

Runtime error 112 | Oct 17, 2015 |

Fortran runtime error: Sequential READ or WRITE not allowed | May 21, 2015 |

[FORTRAN] Runtime error | Nov 8, 2014 |

Fortran runtime error: End of file | Oct 13, 2013 |

FORTRAN Problem! Runtime Error: End of File | Aug 6, 2013 |

**Physics Forums - The Fusion of Science and Community**