Factorial function
1. Definition: The factorial of an integer "n" is the following product: factorial = 1 x 2 x 3 x 4 x ... x n . Written as n!. Here we have used two methods, the recursive method and the iterative method. The first one is more compact.. Two methods in C language: #include#include // Recursive function int factorial (int n) { if (n <= 1) return 1; else return n * factorial (n-1); } //Iterative functions //1. int factorial1(int n) { int i; int facto = 1; for(i=n;i>=1;i--) { facto=facto*i; } return facto; } //2. int factorial2(int n) { int i; int facto = 1; for(i=1; i<=n; i++) { facto= facto*i; } return facto; } int main() { int n; printf("\n Enter an integer\n"); scanf("%d",&n); printf("\n The factorial of %d is %d: \n", n,factorial(n)); printf("\n"); printf("\n The factorial of %d is %d: \n", n,factorial1(n)); printf("\n"); printf("\n The factorial of %d is %d: \n", n,factorial1(n)); return 0; }