I am defining a variable n using scanf in my main function. will the rest of my program know it?
I am solving an equation and have a square root part of my function that sends back the square root value to my main function.
Code:double getSquareRoot ( void ); int main(void) { 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 = getSquareRoot( ); n_factorial = pow(n,n) * exp(-n) * sqrt_solved; printf("%.0f! equals approximately %.5f \n", n, n_factorial); return EXIT_SUCCESS; } double getSquareRoot (void) { double n; // User defines the factorial double sqrt_partial; double sqrt_solved; printf("Please enter a positive integer: "): scanf("%lf", &n); sqrt_partial = (2.0 * n) + (1.0 / 3.0); sqrt_solved = sqrt(sqrt_partial * PI); retun sqrt_solved; }



LinkBack URL
About LinkBacks


