**Problem:-**Write a Hackerrank Solution For Day 9: Recursion or Hacker Rank Solution Program In C++ 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.

**Logic:-**For 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 syntax of Recursion after that with the help of example we will solve a problem. For Recursion first, we need to know the function and declare the function above 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.

**Check this:-**

1. Hackerrank Solution For Day 0: Hello, World.

2. Hackerrank Solution For Day 1: Data Types.

**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();

}

**Also Check:-**

3. Hackerrank Solution For Day 2: Operators.

4. Hackerrank Solution For Day 3: Intro to Conditional Statements

**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 with the full explanation.

**Important:-**If any readers want to write a post for our Programming community please click here Or you have a better solution and you want to publish your solution send the solution I will publish your post / Article and you can add 2 backlinks + you can earn credits.

**Recently Updated Post:-**

6. Hacker Rank Solution For Day 5: Loops

7. Hackerrank Solution For Day 6: Let's Review

8. Hackerrank Solution For Day 7: Arrays

9. Hacker Rank Solution For Day 8: Dictionaries and Maps

Copy the colored code and paste it into hacker rank editor. If you have any query feel free to share with me, and if you like my work please share, comments and subscribe for our new and latest post related to programming this will help you update all about new post this Article.

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

**Submit Your Solution Here:- Click Here**

**Solution:-**

#include <cmath>

#include <cstdio>

#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

int factorial(int num) ;

{

int n;

cin >> n;

cout << factorial(n) << endl;

return 0;

}

{

if(num == 1)

{

return 1;

}

else

{

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

}

}

**Output:-**

**You May Also Like:-**

## No comments:

## Post a Comment