Hello Guys, Today is this article we are taking about Recursion.
👉 Problem :- Find odd-even number using Recursion ?
Let’s start today’s article…
• What is recursion?
=> Recursion mean calling itself till condition not true. A function call itself that’s function called Recursive function.
=> We are finding odd-even number by dividing 2. When the reminder is 0 it’s mean the number is even or reminder is 1, it is odd number. Right…
We are using same logic in today’s solving problem using recursion but different.
👉 Let’s start solving problems
• First we create a function and pass one parameter. As following 👇
• We are using same logic as we use always to find odd even number but in this problem we are consider if the parameter’s value is 0 it is even or if it’s value is 1 it means number is odd.
• Now time to use recursion function but before using recursion we simply decrease parameter ‘num’ value by 2.
Because odd and even number difference is 2 for example 1 and 3 difference is 2 and also 2 and 4 difference is 2. See below 👇
• In the above code, in a line number 14 we are calling a function that’s mean it will call itself till when given condition not true.
🙏 Thanks for reading…
👉 Stay with us for more….