What is a Factorial? How to Calculate Factorials with Examples (2024)

/ #Advanced Mathematics
What is a Factorial? How to Calculate Factorials with Examples (1)
Ilenia
What is a Factorial? How to Calculate Factorials with Examples (2)

A factorial is a mathematical operation that you write like this: n!. It represents the multiplication of all numbers between 1 and n.

So if you were to have 3!, for example, you'd compute 3 x 2 x 1 (which = 6). Let's see how it works with some more examples.

Definition of a Factorial

The factorial of a number is the multiplication of all the numbers between 1 and the number itself. It is written like this: n!. So the factorial of 2 is 2! (= 1 × 2).

To calculate a factorial you need to know two things:

  1. 0! = 1
  2. n! = (n - 1)! × n

The factorial of 0 has value of 1, and the factorial of a number n is equal to the multiplication between the number n and the factorial of n-1.

For example, 5! is equal to 4! × 5.

Here the first few factorial values to give you an idea of how this works:

FactorialMultiplicationResult
0!11
1!11
2!1 × 22
3!1 × 2 × 36
4!1 × 2 × 3 × 424
5!1 × 2 × 3 × 4 × 5120
6!1 × 2 × 3 × 4 × 5 × 6720
7!1 × 2 × 3 × 4 × 5 × 6 × 75040
8!1 × 2 × 3 × 4 × 5 × 6 × 7 × 840,320
9!1 × 2 × 3 × 4 × 5 × 6 × 7 × 8 × 9362,880

What is a Factorial Used For?

Practically speaking, a factorial is the number of different permutations you can have with n items: 3 items can be arranged in exactly 6 different ways (expressed as 3!).

For example, let's see all the arrangements you can have with the three items, A, B and C:

ABCACBBACBCACABCBA

And in fact, 3! = 6.

How to Calculate the Factorial of 0

Looking at the factorial from this point of view, what's the factorial of 0?

Well, how many different ways can you arrange 0 elements?

There is exactly 1 way to arrange zero elements. And that's making a sequence of zero elements.

Factorial Use Cases

You typically use a factorial when you have a problem related to the number of possible arrangements. Let's look at some example problems.

Factorial example problem 1: the letters in the word "camper"

How many different ways can you arrange the letters of the word camper?

The word camper has 6 letters, so the number of possible arrangements is given by the factorial of 6: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720. That would have been a pretty big number of arrangements to find by hand, wouldn't it?

Factorial example problem 2: drawing colored balls from a bag

Let's say there are three balls in a bag – one green, one blue, and one yellow.

If you draw the three balls in sequence, what chance is there that you'll get the yellow first, the green one second, and the blue one last?

Maybe now you are wondering what chances have to do with factorials – well, in a moment you will see.

There are 6 possible sequences in which the balls can be drawn: 3! = 6.

There is a chance of 1 over the total number of possibilities to get the yellow-green-blue sequence, so that is 1/(3!) or 1/6 or 16.7% chance to get the desired outcome.

How to Calculate a Factorial Programmatically with JavaScript

There are two ways to calculate factorials programmatically in JavaScript:

How to calculate a factorial in JS with recursion

Let's get back to the two things to know when calculating a factorial – that is 0! = 1 and n! = (n - 1)! × n. We can use the first one to create the base case of the recursive function, because in that case we know the result already.

function factorial(n) { if (n === 0) { return 1; }}

The second thing to know about how to calculate a factorial, n! = (n - 1)! × n, can be the recursive case.

function factorial(n) { if (n === 0) { return 1; } else { return factorial(n-1) * n; }}

How to calculate a factorial with a JavaScript while loop

We said before that 0! = 1. So, to calculate the factorial of a number with a loop, we can initialize a variable to 1, and multiply the numbers from n to 1 by the variable inside the loop.

In this way, if the input is higher than 1, the output will easily be 1.

function factorial(n) { let result = 1; for (n > 1) { result *= n; n--; } return result;}

Conclusion

The factorial is a pretty important operator to know if you are interested in statistics and probabilities.

In this article you have learned a how to calculate a factorial, a simple application, and you have seen how to calculate it using JavaScript.

Have fun with it!

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

What is a Factorial? How to Calculate Factorials with Examples (3)
Ilenia

Read more posts.

If this article was helpful, .

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

ADVERTIsem*nT

What is a Factorial? How to Calculate Factorials with Examples (2024)

FAQs

What is a Factorial? How to Calculate Factorials with Examples? ›

The factorial sign is an exclamation point and it means to start with the number and multiply by each previous integer until reaching 1. For example, 5! = 5 * 4 * 3 * 2 * 1 = 120.

How do you calculate a factorial? ›

A factorial is a mathematical operation that you write like this: n! . It represents the multiplication of all numbers between 1 and n. So if you were to have 3! , for example, you'd compute 3 x 2 x 1 (which = 6).

What is factorial with example? ›

In short, a factorial is a function that multiplies a number by every number below it till 1. For example, the factorial of 3 represents the multiplication of numbers 3, 2, 1, i.e. 3! = 3 × 2 × 1 and is equal to 6.

What is the quick formula for factorials? ›

n! = n × (n – 1) × (n – 2) × … × 1 = n × (n – 1)! The factorial formula is used in many areas, specifically in permutations and combinations of mathematics.

What is a factorial of 24? ›

When you come across a factorial problem in math, you'll see an exclamation symbol (!) to represent the factorial. In math, we define factorial as the product of a certain integer with all the positive integers below it. So, 3! is 3 * 2 * 1. So, 24! is 24 * 23 * 21 * all the way down to * 1.

How big is 52 factorial? ›

52! is approximately 8.0658e67. For an exact representation, view a factorial table or try a "new-school" calculator, one that understands long integers. A billion years currently equals 3.155692608e16 seconds; however, the addition of leap seconds due to the deceleration of Earth's orbit introduces some variation.

What is factorial for dummies? ›

To calculate factorial of any number n i.e., n!, multiply all integers from 1 to n together. For example, 3! = 3 × 2 × 1 = 6.

What is a real life example of a factorial? ›

different ways to shuffle a deck of cards. Similarly, if there are two toys, you can arrange them in two different ways, and if you have three toys, there are six ways you can arrange them. The word candy has 5 letters, so your answer is 5! = 5 x 4 x 3 x 2 x 1 = 120 ways.

How to solve factorial problems? ›

You can follow these steps to solve for a factorial:
  1. Determine the number. Determine the number you are finding the factorial of. ...
  2. Write the sequence. Using the factorial formula, you can write out the sequence of numbers that you'll multiply. ...
  3. Multiply the numbers.
Oct 22, 2023

Is there a faster way to calculate factorials? ›

The best algorithm that is known is to express the factorial as a product of prime powers. One can quickly determine the primes as well as the right power for each prime using a sieve approach. Computing each power can be done efficiently using repeated squaring, and then the factors are multiplied together.

What is the rule for factorial? ›

In mathematics, the factorial of a number is found by the multiplication of the number with every positive integer less than that. So, n!= n × (n-1) × (n-2) × (n-3) × ..... × 3 × 2 × 1.

What is the factorial formula simplified? ›

A factorial is a function that multiplies a number by every number below it. For example 5!= 5*4*3*2*1=120. The function is used, among other things, to find the number of ways “n” objects can be arranged.

How do you explain Factorials? ›

A factorial is a mathematical function represented by an exclamation mark, The symbol x! means to start with a positive integer, x, and multiply by each previous integer until reaching 1. The mathematical factorial definition is x!= x * (x-1) * (x-2) * (x-3) ... 1.

How do you find the digit of a factorial? ›

Count digits in a factorial using Kamenetsky's Formula
  1. Input : n = 1. Output : 1. 1! = 1, hence number of digits is 1.
  2. Input : 5. Output : 3. 5! = 120, i.e., 3 digits.
  3. Input : 10. Output : 7. 10! = 3628800, i.e., 7 digits.
  4. Input : 50000000. Output : 363233781.
  5. Input : 1000000000. Output : 8565705523.
Jun 24, 2024

What's the factorial of 200? ›

The factorial of 200 is 78865786736479050355236321393218506229513597768717326329474253324435944996340334292030428401198462390417721213891963883025764279024263710506192662495282993111346285727076331723739698894392244562145166424025403329186413122742829485327752424240757390324032125740557956866022603190417032406235170085 ...

How to calculate 20 factorial? ›

Solution: A factorial of a number is the function that multiplies the number by every natural number below it. The Factorial of n is denoted by n! Thus, the factorial of 20 is 2432902008176640000.

What does 7 factorial mean? ›

factorial, in mathematics, the product of all positive integers less than or equal to a given positive integer and denoted by that integer and an exclamation point. Thus, factorial seven is written 7!, meaning 1 × 2 × 3 × 4 × 5 × 6 × 7.

How many zeros are in 25 factorial? ›

25! ∴ No. of zeroes in the end is 6.

References

Top Articles
7Hitmovies Punjabi Movies
N-Vu Login
Automated refuse, recycling for most residences; schedule announced | Lehigh Valley Press
Fat Hog Prices Today
Bin Stores in Wisconsin
The 10 Best Restaurants In Freiburg Germany
Nc Maxpreps
Kentucky Downs Entries Today
Monticello Culver's Flavor Of The Day
Jet Ski Rental Conneaut Lake Pa
Dusk
Taylor Swift Seating Chart Nashville
How to Store Boiled Sweets
Insidekp.kp.org Hrconnect
Willam Belli's Husband
Why Is 365 Market Troy Mi On My Bank Statement
Great Clips Grandview Station Marion Reviews
Jayah And Kimora Phone Number
Chamberlain College of Nursing | Tuition & Acceptance Rates 2024
104 Presidential Ct Lafayette La 70503
Preggophili
Cornedbeefapproved
CohhCarnage - Twitch Streamer Profile & Bio - TopTwitchStreamers
Current Students - Pace University Online
Mawal Gameroom Download
Florence Y'alls Standings
Kleinerer: in Sinntal | markt.de
Guide to Cost-Benefit Analysis of Investment Projects Economic appraisal tool for Cohesion Policy 2014-2020
Planned re-opening of Interchange welcomed - but questions still remain
Mark Ronchetti Daughters
Kempsville Recreation Center Pool Schedule
Grays Anatomy Wiki
Kltv Com Big Red Box
First Light Tomorrow Morning
Diana Lolalytics
Compress PDF - quick, online, free
Tmka-19829
Avance Primary Care Morrisville
Today's Gas Price At Buc-Ee's
Woodman's Carpentersville Gas Price
877-292-0545
Sam's Club Gas Prices Deptford Nj
Riverton Wyoming Craigslist
Who Is Responsible for Writing Obituaries After Death? | Pottstown Funeral Home & Crematory
QVC hosts Carolyn Gracie, Dan Hughes among 400 laid off by network's parent company
Content Page
Pathfinder Wrath Of The Righteous Tiefling Traitor
My Eschedule Greatpeople Me
How To Get To Ultra Space Pixelmon
20 Mr. Miyagi Inspirational Quotes For Wisdom
Diablo Spawns Blox Fruits
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6376

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.