I want to make a program in fortran that lists all the pairs of twin prime numbers in a range, n1 to n2, given by the user. I did this, but it doesn't work and I don't know how to fix it:
implicit none
integer n1, n2, p1, p2, i, j, k, m
read(5,*) n1
read(5,*) n2
do i = n1, n2
do m = i, n2
do j = 2,(i-1)
if (mod(i,j) /= 0) then
p1 = i
do k = 2, (m-1)
if (mod(m,k) /= 0) then
p2 = m
if (p2-p1 == 2) then
write(6,*) p1, p2
end if
end if
end do
end if
end do
end do
end do
end
If I put the range 1 to 10, it print several pairs of 8 and 10.