You know, just the other day I was talking to a classmate about how important number theory is to compuer science...
The simplest formula for factoring a number is probably this..
It isn't complete.. but it's enough that you should be able to execute it by hand for small numbers and get the feel of the algorithm.
for (i = 2; i <= n; i++)
while (n is divisible by i)
printf ("%d is a factor.", i);
n /= i;
If I might make a suggestion, try making a program to generate prime numbers, like you run it and the output would be like...
Once you make a program that can do that, you've already made a program that checks to see if a number is prime, and more than likely the method for doing so will easily translate to factoring a number.