I need help with recursion function.
It prints all the prime factors of an input number.

My question is how to modify function so that START-GOTO is replaced by a loop?
Here is the code:

int f(int n,int i)
{

      start:
    if(n==1)
        goto start;
    if(n % i == 0)
    {
        printf("%d",i);
        return f(n/i,i);
    }
    else
    {
        return f(n,i+1);

    }

}

Thanks for replies.

Delete lines 4, 5, 6, and put this in place:

while (n==1)
{
}

Note that your code will loop forever if n is 1. This is almost certainly not what you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.