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..
Code:
for (i = 2; i <= n; i++)
{
while (n is divisible by i)
{
printf ("%d is a factor.", i);
n /= i;
}
}
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.
If I might make a suggestion, try making a program to generate prime numbers, like you run it and the output would be like...
Code:
C:\>prime.exe
2
3
5
7
11
13
17
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.