0

Ok, I have a program that gets the factors of a LCD of a number (recursion). I need help converting it to loop statement :( . Any help will be appreciated. and please add an explanation I would really appreciate it.

#include<stdio.h>
#include<stdlib.h>

void whatIs (int nNum)
{
int nF = 2;
while (nNum % nF != 0)
nF++;
if (nNum != nF)
{
printf("%d ", nF);

whatIs (nNum/nF);
}
else
printf("%d.", nF);
}

int main()
{
    int nNum;
    scanf("%d",&nNum);
    whatIs(nNum);
    system("pause");
}
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Adak
0

No, this something you can easily do yourself, and just involves a bit of problem solving. You NEED to develop your problem solving, or you can't program worth a darn.

Work through it by hand, and see what kind of loops you're using!

Put some sweat into it! ;) Don't look at the recursive code - don't look at any code, right now. Learn how YOU would solve for LCD, using a loop (which is very natural, btw)

Edited by Adak: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.