Factor a number by looking for primes, because if a factor is not prime it can be factored into primes. Let N be the number to be factored. When you find a prime that divides into N, you add the divisor to the "factor list" and reduce N.
Use a list a list of primes in ascending value -- 2, 3, 5, 7, 11, 13 -- to control the algorithm. For example, to factor 19 try to divide by 2, 3, 5, 7, 11 and 13. Each time the division fails, so 19 is prime. To factor 143, you would try -- and fail -- to divide 143 by 2, 3, 5 and 7. When you try to divide by 11 you succeed, so 11 is added to the factor list and the number under consideration is 143/11 = 13. Now try to divide 13 by 2, 3, 5, 7 then by 11. None of these numbers divides equally. Therefore 13 is prime and gets added to the factor list. The conclusion is that 143 = 11 X 13.
Stop checking for prime divisors when you have checked all the primes up to the square root of the number to be factored. For example, if you are checking to see if 91 is prime (finding all the factors of 91), you only need to check 2, 3, 5 and 7. The next prime is 11 and 11 X 11 = 121, which is bigger than 91. If one factor is greater than the square root, the other factor will be greater than the square root.