+ 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

7th Nov 2021, 7:24 AM
Zarediq Bat
Zarediq Bat - avatar
7 Respostas
7th Nov 2021, 8:42 AM
JaScript
JaScript - avatar
+ 5
Zarediq Bat You just gave yourself best answer and an upvote. Why bother asking us if you are right
7th Nov 2021, 7:51 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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.
7th Nov 2021, 9:07 AM
Solo
Solo - avatar
+ 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.
7th Nov 2021, 8:25 AM
A͢J
A͢J - avatar
0
Hi bro
7th Nov 2021, 4:17 PM
james rubandavid
0
I am c# course Leni to explain bro please
7th Nov 2021, 4:18 PM
james rubandavid
- 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?
7th Nov 2021, 7:47 AM
Zarediq Bat
Zarediq Bat - avatar