I'm working on this problem where you have a variable n and you want to determine if n! is in a certain range. That is easy but the input data is giving a value for n that is less than zero.
Is there anything that I don't know that says what to do when n < 0?
I learned that factorial was defined recursively as:
f(n) = 1, 0 >= n >= 1
n*f(n-1), n > 1
However, when I implement this I get a wrong answer.
The limit is 10000 - 6227020800. So then n can only be in the range [8,13]. Is there anything I am missing?
Say I get f(-1)? Then what?
Non Negatives Factorials
Started by chili5, Sep 12 2009 03:13 PM
4 replies to this topic
#1
Posted 12 September 2009 - 03:13 PM
|
|
|
#2
Posted 12 September 2009 - 05:55 PM
Short answer: (-1)! is not defined.
Long answer: look at Math Forum - Ask Dr. Math and Math Forum: Ask Dr. Math FAQ: 0! = 1
Most likely, you're running into an overflow condition.
Long answer: look at Math Forum - Ask Dr. Math and Math Forum: Ask Dr. Math FAQ: 0! = 1
Most likely, you're running into an overflow condition.
#3
Posted 13 September 2009 - 01:55 AM
Thanks. I got it. This problem is wrong then.
When you are given a negative integer that is even, you have to output Underflow, and if it is odd, output Overflow. This is a bad problem. :(
When you are given a negative integer that is even, you have to output Underflow, and if it is odd, output Overflow. This is a bad problem. :(
#4
Posted 13 September 2009 - 10:15 AM
#5
Posted 13 September 2009 - 10:20 AM
Yes.
The problem title is "Factorial - You Must Be Kidding me!!!!"
Just realized my title is misleading. :P
The problem title is "Factorial - You Must Be Kidding me!!!!"
Just realized my title is misleading. :P


Sign In
Create Account


Back to top









