Page 1 of 1

What is factorial?

Posted: Tue Jun 28, 2011 7:16 am
by Neo
The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,

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;
}

Re: What is factorial?

Posted: Thu Sep 08, 2011 9:35 pm
by AndyCharles
Hey friends.

Very few things have been solved in mathematics, and there are even fewer things that we understand, Factorial means multiple all the integers up to the number given, starting at 1. 0!=1 by convention.

2*2*3*4*5=240

Thanks a lot again
Andy Charles

Re: What is factorial?

Posted: Thu Sep 08, 2011 10:10 pm
by Neo
2*2*3*4*5=240
This is incorrect. 5! = 1 x 2 x 3 x 4 x 5 = 120