In: Computer Science
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../include/cis1057.h"
/*
* Programmer: << MA >>
* Class: Introduction to C Programming 1057 Spring 2019
Section 004
* Assignment: Number 5 “estimate the value of a factorial using
Gosper's algorithm."
* Date: << 02-19-2019 >>
* Version: 1
* Description: Program will prompt for some data, read in the
values, perform
the calculation using library math functions, and display the
result.
* File: lab5.c
*/
# define M_PI 3.14159265358979323846 /* pi */
# define M_E 2.7182818284590452354 /* e */
# define N_COEFF 2
# define CONST 1
int prompt_and_return_integer( const char *prompt );
double estimate_gospers_algorithm( const double n );
void display_results( const double answer );
int main ()
{
const char prompt_1;
double A,B ;
B = prompt_and_return_integer(&prompt_1);
A = estimate_gospers_algorithm(B);
display_results(A);
return EXIT_SUCCESS;
}
int prompt_and_return_integer( const char *prompt )
{
printf("Please enter a positive integer: ");
scanf("%lf", &*prompt);
return *prompt;
}
double estimate_gospers_algorithm( const double n )
{
double squrt_partial; // Gosper's formula under the square root,
leaves out PI
double squrt_solved; // sqrt_part square rooted
double my_result; // powers multipled by the solved square
root
double n_power;
double e_power;
squrt_partial = (N_COEFF * n) + CONST;
squrt_solved = sqrt(squrt_partial * M_PI);
n_power = pow(n,n);
e_power = pow(M_E,-n);
return n_power * e_power * squrt_solved;
}
void display_results( const double answer )
{
printf( " the factorial is %0.2f.\n", answer);
return;
}
my output is coming wrong can somebody help me to fix the problem?
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*
* Programmer: << MA >>
* Class: Introduction to C Programming 1057 Spring 2019
Section 004
* Assignment: Number 5 “estimate the value of a factorial using
Gosper's algorithm."
* Date: << 02-19-2019 >>
* Version: 1
* Description: Program will prompt for some data, read in the
values, perform
the calculation using library math functions, and display the
result.
* File: lab5.c
*/
# define M_PI 3.14159265358979323846 /* pi */
# define M_E 2.7182818284590452354 /* e */
# define N_COEFF 2
# define CONST 1
double prompt_and_return_integer( const char *prompt
);
double estimate_gospers_algorithm( const double n );
void display_results( const double answer );
int main ()
{
const char *prompt_1="Please enter a positive integer: ";
double A,B ;
B = prompt_and_return_integer(prompt_1);
A = estimate_gospers_algorithm(B);
display_results(A);
return EXIT_SUCCESS;
}
double prompt_and_return_integer( const char *prompt )
{
double n;
printf(prompt);
scanf("%lf", &n);
return n;
}
double estimate_gospers_algorithm( const double n )
{
double squrt_partial; // Gosper's formula under the square root,
leaves out PI
double squrt_solved; // sqrt_part square rooted
double my_result; // powers multipled by the solved square
root
double n_power;
double e_power;
squrt_partial = (N_COEFF * n) + CONST;
squrt_solved = sqrt(squrt_partial * M_PI);
n_power = pow(n,n);
e_power = pow(M_E,-n);
return n_power * e_power * squrt_solved;
}
void display_results( const double answer )
{
printf( " the factorial is %0.2f. ", answer);
return;
}
Kindly revert for any queries
Thanks.