How to find the factorial of a number

//
// recursive version
//

int Factorial(int Num) {

  If(num > 0)
  return Num * Factorial(Num– 1);
  else
    return 1;
}

//
// iterative version
//

int Factorial(int Num) {
  int I
  int result = 1;

  for (I = Num; I > 0; I--) {
    result = result * I;
  }

  return result;
}
Chitra
Chitra

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in