How to resolve the algorithm Factorial step by step in the Rapira programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Factorial step by step in the Rapira programming language
Table of Contents
Problem Statement
Write a function to return the factorial of a number. Solutions can be iterative or recursive. Support for trapping negative n errors is optional.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Factorial step by step in the Rapira programming language
Source code in the rapira programming language
Фун Факт(n)
f := 1
для i от 1 до n
f := f * i
кц
Возврат f
Кон Фун
Фун Факт(n)
Если n = 1
Возврат 1
Иначе
Возврат n * Факт(n - 1)
Всё
Кон Фун
Проц Старт()
n := ВводЦел('Введите число (n <= 12) :')
печать 'n! = '
печать Факт(n)
Кон проц
fun factorial(number)
if number = 0 then
return 1
fi
return number * factorial(number - 1)
end
You may also check:How to resolve the algorithm Stack step by step in the SenseTalk programming language
You may also check:How to resolve the algorithm Hamming numbers step by step in the Julia programming language
You may also check:How to resolve the algorithm Range extraction step by step in the K programming language
You may also check:How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the C# programming language
You may also check:How to resolve the algorithm Commatizing numbers step by step in the Scala programming language