29 July 2013

factorial number program in c#

public static int Factorial(int n)
 {
 int FactorialValue = 1;
 for (int i = n; i > 0; i--)
 {
 FactorialValue = FactorialValue * i;
 }
 return FactorialValue;
 }
 public static int recursiveFactorial(int n)
 {
 if (n > 1)
 {
 return n * recursiveFactorial(n - 1);
 }
 else
 {
 return 1;
 }
 }
 public static int recursiveFactorialIntermediate(int n, int[] nArray)
 {
 if (n > 1)
 {
 nArray[n - 1] = n * recursiveFactorialIntermediate(n - 1, nArray);
 return nArray[n - 1];
 }
 else
 {
 return 1;
 }
 }

No comments:

Post a Comment