Get a list of prime numbers, see for example
http://primes.utm.edu/lists/small/
Then go up the list, see if any of them is a factor. If it is, divide your number n, by that prime, and repeat the process with the new value. You store all the prime values. For example, 336, you need all primes up to sqrt(336)=18.3... The list is 2 3 5 7 11 13 17
2 is a factor the result of division is 168. For 168, 2 is a factor, then what is left is 84. For 84 2 is a factor, next is 42. For 42 2 is a factor next is 21. For 21 3 is a factor, next is 7. For 7 only 7 is a factor. So your number is 2^4*3*7. To find all factors, get all unique combinations of the 6 primes in this case: (one element) 2,3,7,(two elements)4,6,14,21(three elements) 8,12,28,42,( four elements)16,24,56,84, (five elements)48,112,168,(six elements)336. You may add 1 to this list