Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In the programming language C, please write a code that meets these 4 requirements. Please look at the second picture, which includes important notes on
In the programming language C, please write a code that meets these 4 requirements. Please look at the second picture, which includes important notes on what the code should be like, including a constant macros. thanks!
You MUST compile your code and test is multiple times before submission. Codes that can't be compiled would be graded as zero. For any integer n > 0, n! (n factorial) is defined as the product n* n - 1 * n - 2 ... * 2 * 1. And O! is defined to be 1. It is sometimes useful to have a closed-form definition instead; for this purpose, an approximation can be used. R.W. Gosper proposed the following approximation formula: n! z n"en ve 2n + 3 TT a) Create a function takes n as input and returns the approximation for factorial value. b) Create another function takes n as input and computes then returns the accurate value for n! as n * n - 1 * n - 2 ... * 2 * 1. c) Your program should prompt the user to enter an integer n, call both functions to compute the approximate and accurate values for n!, and then display the results. The message displaying the result should look something like this: 5! equals approximately 119.97003 5! is 120 accurately. d) Test the program on nonnegative integers less than 10. (A type int might not accommodate overly large numbers so feel free to store the values in an unsigned int data type). Find the difference between the two results for accurateness, then compute the percent error. Is the approximation a good representation of the actual value? Use printf to display the error. |accurate value - approximate value| percent error = X 100 accurate value Note 1: Be careful with the type conversions. Be sure to use a constant macro for Pl, and use the value of 3.14159265. Note 2: factorials grow quickly, so your compiler might not be able to store the factorial of a large number. Feel free to upgrade your variable type form a typical int to an unsigned long long int and check out the updated storage space for larger numbers. printf ("number of bytes integer occupies on my computer: %d,"sizeof(int)); printf ("number of bytes long long integer occupies on my computer: %d,"sizeof(long long int)); The above statements would display how many bytes each data type occupies on your system. Note 3: Make sure negative numbers are avoided for factorial calculations. Each section is worth 25 points for a total of 100 pointsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started