computing with numbers in mathematicsfactorial is often denoted with an exclamation (!the factorial of whole number is defined as nn( )( ( this happens to be the number of distinct arrangements for items given six itemswe compute ( )( )( )( )( )( possible arrangements let' write program that will compute the factorial of number entered by the user the basic outline of our program follows an inputprocessoutput pattern input number to take factorial ofn compute factorial of nfact output fact obviouslythe tricky part here is in the second step how do we actually compute the factoriallet' try one by hand to get an idea for the process in computing the factorial of we first multiply ( then we take that result and do another multiplication ( this result is multiplied by three ( finallythis result is multiplied by ( according to the definitionwe then multiply this result by but that won' change the final value of now let' try to think about the algorithm more generally what is actually going on herewe are doing repeated multiplicationsand as we go alongwe keep track of the running product this is very common algorithmic pattern called an accumulator we build upor accumulatea final value piece by piece to accomplish this in programwe will use an accumulator variable and loop structure the general pattern looks like thisinitialize the accumulator variable loop until final result is reached update the value of accumulator variable realizing this is the pattern that solves the factorial problemwe just need to fill in the details we will be accumulating the factorial let' keep it in variable called fact each time through the loopwe need to multiply fact by one of the factors ( ) it looks like we should use for loop that iterates over this sequence of factors for exampleto compute the factorial of we need loop that works like thisfact for factor in [ , , , , , ]fact fact factor take minute to trace through the execution of this loop and convince yourself that it works when the loop body first executesfact has the value and factor is sothe new value of fact is the next time through the loopfactor will be and fact is updated to the pattern continues for each successive factor until the final result of has been accumulated the initial assignment of to fact before the loop is essential to get the loop started each time through the loop body (including the first)the current value of fact is used to compute the next value the initialization ensures that fact has value on the very first iteration whenever you