Factorial in Pascal: how to calculate. Program Examples

Programming training goes from simple to complex. Having mastered the data types and language operators, they move on to cyclic constructions. There are countless tasks for cycles: from the output of numbers in a column to the calculation of amounts using complex formulas. Nevertheless, novice programmers have the question: "How to calculate the factorial in Pascal?"

factorial in pascal




There are at least three ways to accomplish a task. They differ in the operators used.

Mathematical Information

Before proceeding to the construction of algorithms and writing programs, you should study the theory. In mathematics, the factorial is the product of an integer for which an expression is calculated, positive integers less than it.

An example helps to understand the definition. Suppose you want to find the factorial for the number 3. Solution: 3! = 3 * 2 * 1 = 6.

, . : . , : 0! = 1.

finding factorial




– . , . , "".





.

program in pascal




, . :

while {} do {_};

: {}, {_}.

, :

  • 2 – n, ;
  • 6 – ;
  • 7 – ;
  • 8 – fact, n;
  • 9 – - ;
  • 10 – .

"" repeat.

factorial in pascal program




: repeat {_} until {};





, , :

  • 2 – n , ;
  • 7 – ;
  • 8, 9 – i;
  • 10 – ;
  • 11 – , , .

"" . – for, i .

factorial in pascal program




: for {_} to {_} do {_}.

( ):

  • 2 – n , ;
  • 6 – – ;
  • 7 – ;
  • 8 – fact;
  • 9 – .

, integer. "" . – - longint .




All Articles