fortran:编写一个判断素数的外部函数子程序,在主程序中输入一个整数,调用外部函数
只能写出不含子程序的代码,实在不会改成子程序
function isPrimeNumber(n) result(res)
implicit none
integer, intent(in):: n
logical res
integer i
res = .true.
do i = 2, int(sqrt(n+1.0))
if(mod(n,i)==0) then
res = .false.
exit
end if
end do
end function
program Test
implicit none
integer n
logical Lgc
logical, external::isPrimeNumber
read(*,*) n
Lgc = isPrimeNumber(n)
if(Lgc) then
print*,'yes'
else
print*,'no'
end if
end program