# Thread: Problem with simple Factorial Estimation

1. ## Problem with simple Factorial Estimation

The assignment was to create a program to estimate the factorial of a positive integer using Gosper's formula. I changed it to display intermediate values to find the error, and it looks like root_part is only using the "2n" and not the full "2n + 1/3", but I can't figure out why it's doing that. Reversing them had no effect either. The rest seems accurate given the wrong root_part value.

Any help would be greatly appreciated.

Code:
```#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int
main(void)
{
double  n,
root_part,
root_solved,
n_factorial;
printf("Enter a positive integer> ");
scanf("%lf", &n);

root_partial = (1 / 3) + (2 * n);
printf("Variable root_part = %f \n", root_part);

root_solved = sqrt(root_part * PI);
printf("Variable root_solved = %f \n", root_solved);

n_factorial = (pow(n,n) * exp(-n)) * root_solved;
printf("%.0f! equals approximately %.5f \n", n, n_factorial);

return(0);
}```

2. 1/3 = 0
1.0/3.0 = .333333~

Quzah.

3. Thanks for the quick reply. Fixed everything

4. Originally Posted by Arthurdent
Thanks for the quick reply. Fixed everything
Ahhh... 42.... another Hitchiker's Guide fan!

Welcome to the forums.

5. Originally Posted by CommonTater
Ahhh... 42.... another Hitchiker's Guide fan!

Welcome to the forums.
Nah, it's just a coincidense... ( But a good book! )

6. Originally Posted by Sipher
Nah, it's just a coincidense... ( But a good book! )
Darn... I was so looking forward to the "He's got a TOWEL... run away, run away!" line.

7. Originally Posted by CommonTater
Darn... I was so looking forward to the "He's got a TOWEL... run away, run away!" line.
lol, it's been years since I read this book, yet I still remember it. The author's way of comparing Earth's with Milky Way's bureaucracy was, by my opinion, hilarious! Hehe, the symmenty of events is also outstanding!

8. Originally Posted by Sipher
lol, it's been years since I read this book, yet I still remember it. The author's way of comparing Earth's with Milky Way's bureaucracy was, by my opinion, hilarious! Hehe, the symmenty of events is also outstanding!
Read the book and have the movie... frankly I liked the movie better... "I'm so depressed"...