mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-25 21:58:57 +01:00
Revert "factorial feature implementation"
This reverts commit cdee13e690
.
This commit is contained in:
parent
cdee13e690
commit
e62c3bbb11
2 changed files with 0 additions and 40 deletions
|
@ -53,7 +53,6 @@
|
|||
* [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb)
|
||||
* [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb)
|
||||
* [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb)
|
||||
* [Factorial](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial.rb)
|
||||
* [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb)
|
||||
* [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb)
|
||||
* [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb)
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
# A ruby program to find factorial of a given integer
|
||||
# Factorial of a given integer is defined as the product of all the positive integers less than or equal to the given integer
|
||||
# Mathematical representation: n! = n * (n - 1) * (n - 2) * ... * 1
|
||||
|
||||
def factorial(number)
|
||||
input = number
|
||||
factorial = 1
|
||||
if number < 0
|
||||
"Please check your input number! The given number is a negative number."
|
||||
else
|
||||
while number > 0
|
||||
factorial *= number
|
||||
number -= 1
|
||||
end
|
||||
"The factorial of #{input} is #{factorial}."
|
||||
end
|
||||
rescue
|
||||
"Error: Please provide integer only!"
|
||||
end
|
||||
|
||||
# Valid inputs
|
||||
puts factorial(0)
|
||||
# The factorial of 0 is 1.
|
||||
|
||||
puts factorial(10)
|
||||
# The factorial of 10 is 3628800.
|
||||
|
||||
puts factorial(1)
|
||||
# The factorial of 1 is 1.
|
||||
|
||||
puts factorial(-5)
|
||||
# Please check your input number! The given number is a negative number.
|
||||
|
||||
# Invalid inputs
|
||||
puts factorial("a")
|
||||
# Error: Please provide integer only!
|
||||
|
||||
puts factorial("2")
|
||||
# Error: Please provide integer only!
|
Loading…
Reference in a new issue