The factorial function (article) | Khan Academy (2024)

Want to join the conversation?

Log in

  • Anne

    9 years agoPosted 9 years ago. Direct link to Anne's post “Can someone clarify why 0...”

    Can someone clarify why 0! = 1? I'm really getting lost on the last paragraph, specifically:

    "It's the product of all integers greater than or equal to 1 and less than or equal to 0. But there are no such integers. Therefore, we define 0! to equal the identity for multiplication, which is 1."

    (33 votes)

    • Cameron

      9 years agoPosted 9 years ago. Direct link to Cameron's post “n! is the product of all ...”

      The factorial function (article) | Khan Academy (4)

      The factorial function (article) | Khan Academy (5)

      The factorial function (article) | Khan Academy (6)

      n! is the product of all integers greater than or equal to 1 and less than or equal to n
      or more simply:
      the product of all integers from 1 to n (starting at 1 and going up to n)
      i.e. 1 * 2 * 3 * 4 * 5 * ... * n-1 * n

      so when n=0 we have
      the product of all integers from 1 to 0 (starting at 1 and going up to 0)
      But 1 is already larger than 0 so there are no integers from 1 to 0 (counting up)
      So what do we use for the product of no integers ?
      We use 1.
      Why ?
      Because it is convenient, it makes makes math easier, and most importantly it makes our formulas that could calculate 0! make sense. The article gives an example of how it makes our formulas make sense. It shows that when we calculate the number of ways of choosing a group of n items from n items (which should obviously be 1), the formula needs 0! to be 1.

      Hope this makes sense

      (81 votes)

  • Maddie Walker

    6 years agoPosted 6 years ago. Direct link to Maddie Walker's post “I'm still really confused...”

    I'm still really confused on this subject. If one of y'all could explain how n and n! work in a really simple almost kindergarten version, that would be amazing! I'm trying to relate this so something that I have already learned/know about so the concept will be easily identified and understandable. Thanks in advance!

    (9 votes)

    • Cameron

      6 years agoPosted 6 years ago. Direct link to Cameron's post “n! is the product (multip...”

      The factorial function (article) | Khan Academy (10)

      n! is the product (multiplication) of all the whole numbers from n to 1
      e.g.
      3! = 3 * 2 * 1
      2! = 2 * 1
      1! = 1

      0! is a special case. We say that 0! = 1.

      We use factorials when we look at permutations and combinations.
      Permutations tell us how many different ways we can arrange things if their order matters.
      Combinations tells us how many ways we can choose k item from n items if their order does not matter.

      If we have n different items, then we can permute (arrange) them in n! different arrangements.
      e.g.
      If we have 3 items: A,B,C then there are 3! = 3 * 2 * 1 = 6 different permuations
      Here they are:
      ABC, ACB, BAC, BCA, CAB, CBA

      If we have n items there are n!/(k! * (n-k)!) different combinations of choosing k items from those n items.
      e.g.
      If we 5 items: A,B,C,D,E and we want to choose 2 items at a time then there are:
      5!/( 2! * (5-2)!) = 5! / (2! * 3!) = 120/(2 * 6) = 10 different combinations
      Here they are:
      AB, AC, AD, AE, BC, BD, BE, CD, CE, DE
      Note: CB would be considered as the same combination as BC, because order doesn't matter

      For more info check out:
      https://www.khanacademy.org/math/precalculus/prob-comb/combinatorics-precalc/v/factorial-and-counting-seat-arrangements
      https://www.khanacademy.org/math/precalculus/prob-comb/combinations/v/introduction-to-combinations

      (24 votes)

  • lauren.finkle

    9 years agoPosted 9 years ago. Direct link to lauren.finkle's post “In the for loop when we s...”

    In the for loop when we say result = result * i; how do these two results not override each other? How does the computer know that one result is referring to the previous sum of the multiplications and the other is that value times i?

    (2 votes)

    • jdsutton

      9 years agoPosted 9 years ago. Direct link to jdsutton's post “`result = result * i;` is...”

      The factorial function (article) | Khan Academy (14)

      result = result * i; is really telling the computer to do this:
      1. Compute the value of result * i and store it somewhere
      2. Take the stored value and assign result to that value

      When you use the = operator, the entire right hand side is evaluated to some value, and then that value is put into the left hand side variable. Everything is happening in steps, not all at once.

      (12 votes)

  • Vu Tran

    9 years agoPosted 9 years ago. Direct link to Vu Tran's post “In the example given abov...”

    In the example given above where you have n t-shirts and want to be able to pack only k amount, the given formula is n!/(k!⋅(n−k)!)

    In the permutations course given in the link, the formula is stated to to be n!/(n-k)!

    Can someone explain where the extra k! in the denominator came from?

    (3 votes)

    • Cameron

      9 years agoPosted 9 years ago. Direct link to Cameron's post “n!/(k! (n-k)!) would tell...”

      n!/(k! (n-k)!) would tell you the number of ways you could pick k t-shirts from n shirts where the order does not matter

      n!/(n-k)! would tell you the number of ways you could pick k t-shirts from n shirts where the order matters e.g. the first shirt you pick you write 1 on it, the 2nd shirt you write 2 on it, etc.

      Dividing by k! accounts for the number of ways each selection of k shirts will be counted.
      e.g. Suppose k= 3 and one possible selection of shirts is shirts: 5, 7 and 13
      You could have picked those shirts in these 3! = 6 different ways:
      5 then 7 then 13 or,
      5 then 13 then 7 or,
      7 then 5 then 13 or,
      7 then 13 then 5 or,
      13 then 5 then 7 or,
      13 then 7 then 5

      (8 votes)

  • Barbara DiLucchio

    5 years agoPosted 5 years ago. Direct link to Barbara DiLucchio's post “when you are writing pyth...”

    when you are writing python code for any given factorial say one that a user enters like 11. what if you also need to determine which values are odd and which are even is it true that they are always even? do you ever get odd results going down thru the range values?

    (3 votes)

    • Jesse

      5 years agoPosted 5 years ago. Direct link to Jesse's post “All the results of the fa...”

      All the results of the factorial function are always even UNLESS it's 1! or 0!. Therefore for all n! such that n doesn't equal 0 or 1 the result is even. That's because 0! and 1! equals 1, which is odd.

      This is because an odd number multiplied by an even number is even, and an even number multiplied by an even number is also even. Therefore for every n! where n > 1 an even number is involved, making the answer even.

      Hope that helped!

      (3 votes)

  • Renan Teixeira Ferraz

    5 years agoPosted 5 years ago. Direct link to Renan Teixeira Ferraz's post “The autograder isn't work...”

    The autograder isn't working for me. The console is showing me that the code works, but the autograder doesn't.

    (3 votes)

    • Jesse

      5 years agoPosted 5 years ago. Direct link to Jesse's post “That happened to me too. ...”

      That happened to me too. I reported it and am hoping they'll fix the issue. (the console showed it worked, and my code is just like the code in the hint).

      (2 votes)

  • cmb717

    3 years agoPosted 3 years ago. Direct link to cmb717's post “I can not get the next ch...”

    I can not get the next challenge completed what am i doing wrong? Here is my code (edited to only show relevant parts)

    var result = 1;

    for(var i= result; i>=n; i--) {
    n=i*n;
    }


    I looked through the comments for help but all I could find were Cameron's cryptic answers can I have a more firm hint please. (not saying Cameron did a bad job just saying I can not understand their hints)

    (2 votes)

    • Cameron

      3 years agoPosted 3 years ago. Direct link to Cameron's post “Let's review some for loo...”

      Let's review some for loop basics:

      //This for loop will:
      //-begin the counter at start,
      //-do some stuff each loop
      //-then increment counter
      //until the counter exceeds last
      for( var counter = start; counter <= last; counter++){
      //this is the body where we do some stuff
      }

      A simple for loop that would print out the numbers from 1 to 10 would be:

      for( var i = 1; i <= 10; counter++){
      println(i);
      }

      Many find the BASIC version of this a bit easier to understand:

      FOR I=1 TO 10
      PRINT(I)
      NEXT I

      There are a couple of things that you almost never want to do inside the body of the for loop:
      1) change the value of the counter
      2) change the value of the number you are stepping the counter towards e.g. last in the first example

      Doing either of those usually leads to unpredictable behaviour.

      Here's some extra hints using the hint code:

      var factorial = function(n) {
      //this will set the value of result before we start looping
      var result = ;

      //think about calculating n! by hand
      // n! = 1 * 2 * 3 * ... * n-2 * n-1 * n
      // what number do we start at ?
      // what number do we end at ?
      for(var i = ; i <= ; ) {

      //we need to update the value of result here, so that it
      //will be equal to n! by the time we stop looping

      //changing the counter i, or the value that it is going to, would be bad here
      ;
      }

      //we are returning the value of result here
      //so result should now hold the value of n!
      return result;
      };

      Good Luck

      (3 votes)

  • Matthew Narodowg

    3 years agoPosted 3 years ago. Direct link to Matthew Narodowg's post “my code keeps coming up w...”

    my code keeps coming up with this
    message

    Hm, are you hard-coding the number to count up to?
    idk what i'm doing wrong

    (2 votes)

    • Cameron

      3 years agoPosted 3 years ago. Direct link to Cameron's post “If you put a number in th...”

      If you put a number in the condition of the for loop you'll get that. e.g. i <= 5

      If you put a number like 5 instead of using a variable, that is what is called "hard coding". Hard coding makes your program work for only one specific input. We want our programs to be flexible and work with different inputs, so we use variables.

      (2 votes)

  • SecretCoder

    2 years agoPosted 2 years ago. Direct link to SecretCoder's post “Why do they have a '!' af...”

    Why do they have a '!' after numbers like: 0!, 1!, n!

    (2 votes)

    • Cameron

      2 years agoPosted 2 years ago. Direct link to Cameron's post “From the first paragraph ...”

      From the first paragraph of the article:
      "We indicate the factorial of n by n!. It's just the product of the integers 1 through n. For example, 5! equals 1 * 2 * 3 * 4 * 5 or 120. (Note: Wherever we're talking about the factorial function, all exclamation points refer to the factorial function and are not for emphasis.)"

      (2 votes)

  • Eden Washington

    2 years agoPosted 2 years ago. Direct link to Eden Washington's post “I can't get this complete...”

    I can't get this completed.. I've done the coding statements as I knew how to do

    But I kept on getting
    "Hm, do all your assertions pass?" for this code I was doing, what do i need to add or fix?

    var result = 1;
    for(var i= 0; i<=n; i++) {
    result=(n+1)*(i+1);
    }
    return result;
    };

    (2 votes)

    • Cameron

      2 years agoPosted 2 years ago. Direct link to Cameron's post “The above calculation `re...”

      The above calculation result=(n+1)*(i+1); is incorrect.
      A few things to remember:
      n! = 1 * 2 * 3 * ... * n
      and
      n! = n * (n-1)!
      and
      0! = 1 (which is same as result before the for loop. So, if it skipped the calculations in the for loop it would be nice)

      (2 votes)

The factorial function (article) | Khan Academy (2024)

FAQs

What is the factorial of 100 voice answers? ›

The answer of what is the factorial of 100

is 9.3326215443944E+157.

What is the answer of factorial? ›

The Factorial of a whole number 'n' is defined as the product of that number with every whole number less than or equal to 'n' till 1. For example, the factorial of 4 is 4 × 3 × 2 × 1, which is equal to 24. It is represented using the symbol '!' So, 24 is the value of 4!.

What is the easiest way to solve a factorial? ›

To do factorials, start by determining which number you're computing the factorial for, which will be the number that's in front of the exclamation point. Then, write out all of the numbers that descend sequentially from that number until you get to 1. Finally, multiply all of the numbers together.

Why is 0 factorial 1 khan academy? ›

"It's the product of all integers greater than or equal to 1 and less than or equal to 0. But there are no such integers. Therefore, we define 0! to equal the identity for multiplication, which is 1." Answer Button navigates to signup page • 3 comments.

What does 9.332622 E 157 mean? ›

After calculation, the value of Factorial 100 comes out to be equal to 9.332622e+157.

How big is 1000000 factorial? ›

One million factorial is approximately 8.2639317 × 105,565,708.

What is the best algorithm for factorial? ›

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 basic logic for factorial? ›

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.

Can you simplify a factorial? ›

Simplify factorial quotients by canceling like integers in the numerator and denominator. Multiply all the remaining integers in the numerator. Multiply all the remaining integers in the denominator. Divide the product in the numerator by the product in the denominator.

Is 7 0 undefined? ›

Answer and Explanation:

7 divided by 0 is undefined. This is because it is absolutely impossible to divide a non-zero number by zero.

Is 0 9 undefined? ›

We know 0 divided by any integer excepting 0 is 0. Hence 0/9=0. But when 0/0 i.e. 0 is divided by 0 — it is undefined.

Why can't we divide by 0? ›

As much as we would like to have an answer for "what's 1 divided by 0?" it's sadly impossible to have an answer. The reason, in short, is that whatever we may answer, we will then have to agree that that answer times 0 equals to 1, and that cannot be ​true, because anything times 0 is 0.

What is the factorial of 100 in words? ›

Answer: The approximate value of 100! is 9.3326215443944E+157. The value of 100 factorial (100!) is a large number that can be calculated using mathematical software or calculators designed to handle such computations.

What is 100 factorial exact? ›

Through the means of the formula and using it for the calculation of factorial 100, it can be inferred that the factorial for 100 would be equivalent to 9.332621544 E + 157.

How many zeros are in 100 factorial? ›

So the number of zeros at the end of 100! are 24.

How do you find the number of digits in 100 factorial? ›

The factorial of 100 is the multiplication 100 x 99 x 98 x … x 3 x 2 x 1 in which 100 is multiplied by every whole number below it. The answer is 158-digits long.

References

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6651

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.