[CSC 330] Fortran Code
Andrew J. Pounds
pounds_aj at mercer.edu
Fri Sep 30 10:15:31 EDT 2022
For those of you that are still struggling with getting the in-class
Fortran code assignment done, I have included a working piece of code
that should closely resemble what I gave you for python. Please look
over this and make sure you understand what is going on. You may use
this for your assignment - but if you do please acknowledge in the code
that you are doing that.
program primes
integer :: num1, num2
print *, "What is the first number?"
read *, num1
print *, "What is the second number?"
read *, num2
call printPrimes(num1, num2)
end program primes
subroutine printPrimes(num1, num2)
integer :: num1, num2
interface
logical function isPrime(checknum)
integer :: checknum
end function isPrime
end interface
do i = num1, num2
if ( isPrime(i) ) print *, i
enddo
end subroutine printPrimes
logical function isPrime(check)
integer :: check, numDivisors
numDivisors = 0
do i = 1, check
if ( mod(check,i) .eq. 0 ) numDivisors = numDivisors + 1
enddo
isPrime = numDivisors == 2
return
end function isPrime
--
*Andrew J. Pounds, Ph.D.*
/Professor of Chemistry and Computer Science/
/Director of the Computational Science Program/
/Mercer University, Macon, GA, 31207 (478) 301-5627 /
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc330/attachments/20220930/6a2213a7/attachment.html>
More information about the csc330
mailing list