Prime factorization

I once again struck on a problem with prime numbers, this time, it's about Prime Factorization. I wrote a little recursive code to print out the complete list of prime factors a given unsigned integer u consists of.

This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void Factorize(unsigned u)
{
    for(unsigned i(2);i<u;i++)
    {
        if(u%i == 0)
        {   cout << i;
            if (u!=i)
            {
                cout << "*";
                Factorize(u/i);
            }
        }
    }
}

Obviously, it doesn't work, but I can't for the life of me seem to find the bug.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Factorize(unsigned u)
{
    for(unsigned i(2);i<=u;i++) //(1)
    {
        if(u%i == 0)
        {   cout << i;
            if (u!=i)
            {
                cout << "*";
                Factorize(u/i);
                return;         //(2)
            }
        }
    }
}
..How did I ever look over that? :/
Thanks.
Topic archived. No new replies allowed.