What is factorial?

Mathematics for Computing
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

What is factorial?

Post by Neo » Tue Jun 28, 2011 7:16 am

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;
}
AndyCharles
Corporal
Corporal
Posts: 10
Joined: Tue Jul 26, 2011 7:01 pm

Re: What is factorial?

Post by AndyCharles » Thu Sep 08, 2011 9:35 pm

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
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: What is factorial?

Post by Neo » Thu Sep 08, 2011 10:10 pm

2*2*3*4*5=240
This is incorrect. 5! = 1 x 2 x 3 x 4 x 5 = 120
Post Reply

Return to “Mathematics”