**Problem:- **Write a Hackerrank Solution For Day 9: Recursion or Hacker Rank Solution Program In Python and other languages , For ” Day 9: Recursion ” or Hackerrank 30 days of code Java Solution: Day 9: Recursion solution or Hackerrank solution for 30 Days of Code Challenges or Hackerrank 30 days of code Java Solution, Day 9: Recursion solution, or C/C++ Logic & Problem Solving: Day 9: Recursion.

Join Telegram for Daily job Updates

**Logic:-** For the day 9 recursion solution first you have to know that What is Recursion?. The syntax of Recursion etc. So first we will define a definition of Recursion then the syntax of Recursion after that with the help of an example we will solve a problem. For Recursion first, we need to know the function and declare the function above the main() function and after the declaration, we have to define the function and most important call the function by call by value or call by reference.

What is Recursion:-According to Wikipedia Recursion occurs when a thing is defined in terms of itself or of its type. or in simple words in terms of Function when Function Call it self Called Recursion

**The syntax of Recursion:-** So as we already discuss when a function calls it self-called Recursion.

void Recursion();

int main()

{

Recursion()

}

void Recursion()

{

Recursion();

}

**Explanation:-** So we are taking an example of the factorial program with Recursion. Below is the recursion program of factorial. Let take a value of num is 5, as we know that if we want to factorial of any number we need to multiply all number from 1 to number like **5 * 4 * 3 * 2 * 1 = 120.**

int factorial(int num) // fuction num = 5

{

if(num == 1)

{

return 1;

}

else

{

return (num * (factorial(num-1))); //Recursion

}

}

In return statement Here 5 * (factorial(num-1)) means 5 * 4 and again number reduces by 1 and 5 * 4 * 3 and repeat the process again and again. So this way we can find our solution. I hope you got the problem statement and logic of problem, Now we can solve the problem. try to solve the Fibonacci problem with the help of recursion.

All solution provided here are in C++ (CPP) if you want these solutions in C, and Java comments below or sends a mail with your query like ” day n solution in C / C++ / Java. You can also find more program in below of this post. Check the below solution for the full explanation.

Tip:- Always try to implement the own logic this will help you to solve and building logic. Before copy the program I recommended please read this full article, this will help you to build your own logic.

### Recursion HackerRank solution in Python :

```
def factorial(num):
return 1 if num == 1 else factorial(num - 1) * num
print(factorial(int(input())))
```

### Recursion HackerRank solution in Java :

```
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.close();
System.out.println(factorial(n));
}
private static int factorial(int n) {
if (n == 1) return 1;
return factorial(n - 1) * n;
}
}
```

Day 9 Recursion HackerRank Solution | 30 Days of Code | Python / Java