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);

29th Mar 2017, 9:43 AM
Legend Shees
Legend Shees - avatar
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.
29th Mar 2017, 9:45 AM
Ahri Fox
Ahri Fox - avatar
+ 11
why your name Legend Shees?
30th Mar 2017, 12:08 AM
Agus Mei
Agus Mei - avatar
+ 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
29th Mar 2017, 10:09 AM
Meharban Singh
Meharban Singh - avatar
+ 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.
29th Mar 2017, 9:52 AM
seamiki
seamiki - avatar
+ 1
what??
29th Mar 2017, 9:46 AM
Legend Shees
Legend Shees - avatar