7! = 7 x 6 x 5 x 4 x 3 x 2 x 1
Note that there is a special case when n = 0. i.e.: Factorial 0 or 0!. Factorial 0 is defined as 1.
0! = 1
1! = 1
2! = 2 x 1
(Note: Don't think too much about 0! = 1. Just memorise it).
If you need to learn more on this, there is a well explained wiki page on this here. However it is enough to remember that n! = 1 x 2 x 3 ..... x (n - 3) x (n - 2) x (n - 1) x n
There are two reasons for me to explain a bit about factorial.
1. This is required for both Permutations and Combinations
2. There is a nice example on recursion to implement factorial. Have a look at the following C++ code if you are interested.
Code: Select all
#include <iostream.h>
int factorial (int number) {
int temp;
if (number <= 1){ // Notice the exit condition of the recursive function
return 1;
}
temp = number * factorial(number - 1); // Note the recursive call to same function
return temp;
}
int main (void) {
int number;
cout << "Please enter a positive integer: ";
cin >> number;
if (number < 0){
cout << "That is not a positive integer.\n";
}
else{
cout << number << " factorial is: " << factorial(number) << endl;
}
return 0;
}