0
Attention please
in this code,, static int Fact(int num) { if (num == 1) { return 1; } return num * Fact(num - 1); } explain return num* Fact (num-1);
5 Respostas
+ 16
Will the real Legend Shees please stand up?
I repeat:
Will the real Legend Shees please stand up?
I think we're gonna have a problem here.
+ 11
why your name Legend Shees?
+ 8
factorial of n= n*(n-1)*(n-2)*......*1
Last statement does the same.
Lets say you pass 5 in this method,
then it will return 5*fact(4).Hence this method is called again in fact(4).
it will return 4*fact(3)which will further return 3*fact(2),which will return 2*fact(1).For fact(1),if statement is true,which will return 1.
Hence net return=5*4*3*2*1,which is answer
+ 4
First solution
1read about factorial numbers
2read about recursion
3think your algorithm
4express it in code
Second solution
3.1shortcut: look for "factorial" in the code playground.
4.1Chose a program that suits your taste
5.1Read the finished program to extract the algorythm.
6Edit and tweak the program to personalize it further to your liking.
+ 1
what??