# Problem with simple Factorial Estimation

• 06-16-2011
Arthurdent
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); }```
• 06-16-2011
quzah
1/3 = 0
1.0/3.0 = .333333~

Quzah.
• 06-16-2011
Arthurdent
Thanks for the quick reply. Fixed everything :D
• 06-16-2011
CommonTater
Quote:

Originally Posted by Arthurdent
Thanks for the quick reply. Fixed everything :D

Ahhh... 42.... another Hitchiker's Guide fan!

Welcome to the forums.
• 06-16-2011
GReaper
Quote:

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! :D )
• 06-16-2011
CommonTater
Quote:

Originally Posted by Sipher
Nah, it's just a coincidense... ( But a good book! :D )

Darn... I was so looking forward to the "He's got a TOWEL... run away, run away!" line.
• 06-16-2011
GReaper
Quote:

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! :D
• 06-16-2011
CommonTater
Quote:

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! :D

Read the book and have the movie... frankly I liked the movie better... "I'm so depressed"...