+ 1
Recursion In C#
in c# , recursion is factorial. ex. static int fact(int n) if(n==1) returns 1} return n*fact(n-1) what I'm confused about is what is n-1 ? , why when I change it, it becomes weird
7 Respuestas
+ 4
This will help you:
https://code.sololearn.com/cd853UUOeh4M/?ref=app
+ 5
Zarediq Bat
You just gave yourself best answer and an upvote.
Why bother asking us if you are right
+ 4
Firstly, you made a number of gross errors in this code because of which it will not work, and secondly, the factorial of the number n multiplies a series of consecutive numbers n, and does not add, and thirdly (n-1) is an iterator of a recursive function.
+ 3
Zarediq Bat
There is * not +
n - 1 is used to decrement value by 1 to meet the condition n == 1 so program can stop there and we can get final result.
If you change n-1 to n then program will run forever.
0
Hi bro
0
I am c# course Leni to explain bro please
- 1
I found it. n-1 is a skip number. ex. base if(1)
instruction +
input 5
(n-1
5+4+3+2+1 )
(n-2
5+3+1)
Am I right?