I need to write a program that will print the prime factorization of a number.(adsbygoogle = window.adsbygoogle || []).push({});

Here's what I have so far:

integer:: n,i

print *, "enter integer"

read *, n

do while (n>1)

i=2

if (mod(n,i)==0) then

print *, i

n = n/i

else

i = i+1

end if

end do

end program

I'm just using trial division to find the prime factorization. For some reason, the program works for powers of 2 (4,8,16,32,64, etc.) but nothing else. It will factor a number such as 20 into (2,2) but doesn't go any farther. What is wrong with my program? Why does it stop trial division at i=2?

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

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

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

# Help with simple Fortran program

**Physics Forums | Science Articles, Homework Help, Discussion**