Question: #include #include / / Function Prototypes double calculate _ exp ( double x , int t ) ; double calculate _ sin ( double x
#include
#include
Function Prototypes
double calculateexpdouble x int t;
double calculatesindouble x int t;
double factorialint n;
Main Function
int main
Program header
printfAuthor: Your Name
;
printfClass: Your Class
;
printfDate: Today's Date
;
printfDescription: This program evaluates exponential and sine functions using power series.
;
char option;
double x result, mathh error;
int t;
Display the menu
printfPlease select an option:
;
printfa Evaluate exp function
;
printfb Evaluate sin function
;
Get the user's choice
scanfc &option;
if option a option A
printfValid option
;
Get user inputs for x and t
printfEnter the value for x: ;
scanflf &x;
printfEnter the number of terms t: ;
scanfd &t;
Calculate exp using power series
result calculateexpx t;
Calculate exp using math.h
mathh expx;
Calculate the percentage error
error fabsresult mathh mathh ;
Display the result
printflf d lf lf lf
x t result, mathh error;
else if option b option B
printfValid option
;
Get user inputs for x and t
printfEnter the value for x: ;
scanflf &x;
printfEnter the number of terms t: ;
scanfd &t;
Calculate sin using power series
result calculatesinx t;
Calculate sin using math.h
mathh sinx;
Calculate the percentage error
error fabsresult mathh mathh ;
Display the result
printflf d lf lf lf
x t result, mathh error;
else
printfInvalid option
;
return ;
Function Definitions
double calculateexpdouble x int t
double sum ; Start with x
for int n ; n t; n
sum powx n factorialn;
return sum;
double calculatesindouble x int t
double sum ;
for int n ; n t; n
int coefficient pow n; Alternate between and
sum coefficient powxn factorialn ;
return sum;
double factorialint n
if n
return ;
double fact ;
for int i ; i n; i
fact i;
return fact;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
