15,995,388 members
1.00/5 (3 votes)
See more:
PLease help
its about recursion and multiplying the even numbers

What I have tried:

int fn(){
int n;
n = rand() % 900 + 100;
printf("%d\n", n);
return 0;
}
Posted
Updated 22-Apr-20 0:00am
Comments
Afzaal Ahmad Zeeshan 22-Apr-20 5:55am
You forgot to mention the 2 questions as well as the problems you are having.
Patrice T 22-Apr-20 6:18am
And the questions are ?

## Solution 1

There is no recursion in that code: if `fn` was recursive, then it wouldn't work as there is no way to "limit" it from infinite recursion - you really need to parameter to do that, or you app will just blow the top off the stack and crash.
This is recursive:
C++
```int factorial(int n)
{
if (n <= 1) return 1;
return n * factorial(n - 1);
}```
Because it calls the `factorial` function from within the `factorial` function. Because the parameter value changes each time it gets called, the limiting check of "one or less" prevents infinite recursion, and it finally produces the correct result.

I'd suggest you go back to your course notes for the last lecture, and your homework question and read them again, really carefully!

v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 55 Richard Deeming 50 OriginalGriff 25 RickZeeland 10 Pete O'Hanlon 10
 OriginalGriff 431 Pete O'Hanlon 215 Dave Kreskowiak 115 CPallini 110 CHill60 42

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900