- #1
Sue Parks
- 38
- 0
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).
This is from my command line:
Sues-MacBook-Air:FORTRAN sueparks$ gfortran PRIME.f90
Sues-MacBook-Air:FORTRAN sueparks$ ./MY_PRIME.out
This is from my command line:
Sues-MacBook-Air:FORTRAN sueparks$ gfortran PRIME.f90
Sues-MacBook-Air:FORTRAN sueparks$ ./MY_PRIME.out
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
Last edited by a moderator: