# Splitting up my Gosper's Algorithm into multiple Functions

This is a discussion on Splitting up my Gosper's Algorithm into multiple Functions within the C Programming forums, part of the General Programming Boards category; Code: // Required Libraries #include <stdio.h> #include <stdlib.h> #include <math.h> // Program Defined Specifics #define PROGRAMMER_NAME "Leigh McKenzie" #define PI ...

1. ## Splitting up my Gosper's Algorithm into multiple Functions

Code:
```// Required Libraries

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// Program Defined Specifics

#define PROGRAMMER_NAME "Leigh McKenzie"
#define PI 3.14159
#define E 2.7182818284;

// Start Program

int main(void)
{

double n; // User defines this variable
double sqrt_partial; // Gosper's formula under the square root, leaves out PI
double sqrt_solved; // sqrt_part square rooted
double n_factorial; // powers multipled by the solved square root

printf("ESTIMATE A FACTORIAL NUMBER\n");
printf("This program was written by %s.\n", PROGRAMMER_NAME);

printf("Please enter a positive integer: ");
scanf("%lf", &n);

sqrt_partial = (2.0 * n) + (1.0 + 3.0);

sqrt_solved = sqrt(sqrt_partial * PI);

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

return EXIT_SUCCESS;
}```
I need a function dedicated for the square root part of my problem. How do I split it up properly?

Thanks in advance for the help! this is only my second program

2. What do you include in the "square root part" of your problem? the computation of 'sqrt_partial' and 'sqrt_solved'? or everything between the input and the final result?

3. Does that even compile? You're multiplying by exp which is a function pointer. At best that would produce a garbage result.
You will want to actually call that function instead.

4. Originally Posted by root4
What do you include in the "square root part" of your problem? the computation of 'sqrt_partial' and 'sqrt_solved'? or everything between the input and the final result?
My second function should include the entire square root part of the equation.

5. Originally Posted by locololo2
Code:
`#define E 2.7182818284;`
No! That extra semicolon is going to hurt you badly. Take it away NOW.