0

Recursion

#include <iostream> using namespace std; int factorial(int n) { if (n==1) { return 0; } else { return n - factorial(n-1); } } int main() { cout << factorial(5); } --------------------------------------------- //output 2 ????????????????????????????

14th Jul 2020, 8:01 AM
‎دانیال رضایی نژاد‎
‎دانیال رضایی نژاد‎ - avatar
2 Respostas
+ 1
Use multiplication symbol instead of minus to get result.
15th Jul 2020, 3:10 PM
shubham kumar
shubham kumar - avatar
0
5- factorial(4) 👇 (4 - factorial(3)) 👇 3 - factorial(2) 👇 2 - factorial(1) : 5 - (4 - (3 - (2 - 0))) 5 - (4 - (3 - 2)) 5 - (4 - 1) 5 - 3 2 SO it return 2. Edit : [It won't call, factorial(0)] Edit : دانیال رضایی نژاد whats your question actually? Pls give clarity..
14th Jul 2020, 1:45 PM
Jayakrishna 🇮🇳