kalpana jaiswal

kalpana jaiswal

  • NA
  • 45
  • 9.7k

query about recursion function

Sep 16 2016 2:33 PM
<ol><li><span>using System; </span> </li><li> <br /></li><li><span>namespace InterviewQuestionPart4 </span> </li><li>{ </li><li> <span>class Program </span> </li><li> { </li><li> <span>static void Main(string[] args) </span> </li><li> { </li><li> Console.WriteLine(<span>"Please Enter a Number"); </span> </li><li> <br /></li><li> <span>//read number from user </span> </li><li> <span>int number =Convert.ToInt32(Console.ReadLine()); </span> </li><li> <br /></li><li> <span>//invoke the static method </span> </li><li> <span>double factorial = Factorial(number); </span> </li><li> <br /></li><li> <span>//print the factorial result </span> </li><li> Console.WriteLine(<span>"factorial of"+number+"="+factorial.ToString()); </span> </li><li> <br /></li><li> } </li><li> <span>public static double Factorial(int number) </span> </li><li> { </li><li> <span>if (number == 0) </span> </li><li> <span>return 1; </span> </li><li> <span>return number * Factorial(number-1);//Recursive call </span> </li><li> <br /></li><li> } </li><li> } </li><li>} <br /></li></ol>in the above program when condition is satisfied then its should return 1as output then how the result is return?

Answers (1)