Here is a way of finding the factorial of a number using recursion, i have also added an iterative method of achieving the same result. Note the simplistic nature of recursion.
// Contained here are 2 ways of determining the factorial // of a given value, adjustments need to be made to store // Large values, its just a starting point =) //recurive function int determineFactorialRecursive (int a) { if (a == 1) return 1; //factorial of 1 == 1 else return a * determineFactorialRecursive (a - 1); // Notes:: // recursive approach - Note you are calling the function // determineFactorial recursively. // do some reading and you will find this helpful } //Another way int DetermineFactorialOther (int myFact) { int value; int value2 = 1; for (int i = myFact; i > 1; i--) { value = (i * (i-1)); value2 *= value; i--; } return value2; }
