Like Tree1Likes
  • 1 Post By qny

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. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    3

    Question 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
    Last edited by locololo2; 09-16-2012 at 11:46 AM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    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. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    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.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    3
    Quote Originally Posted by root4 View Post
    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. #5
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    Quote Originally Posted by locololo2 View Post
    Code:
    #define E 2.7182818284;
    No! That extra semicolon is going to hurt you badly. Take it away NOW.
    stahta01 likes this.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,702
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Optimal algorithm for a splitting problem
    By paradox in forum C++ Programming
    Replies: 4
    Last Post: 10-02-2009, 08:01 PM
  2. Splitting a string to retrieve multiple integers
    By Tom_Arch in forum C Programming
    Replies: 2
    Last Post: 04-21-2009, 08:30 AM
  3. Splitting Code Into Multiple Files
    By pobri19 in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2008, 04:21 AM
  4. String splitting algorithm help
    By (TNT) in forum C++ Programming
    Replies: 7
    Last Post: 05-12-2007, 11:28 AM
  5. Splitting a dialog up into multiple classes
    By Just in forum Windows Programming
    Replies: 1
    Last Post: 05-29-2005, 11:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21