78 full screen 4827813 view Problem 1 (35 points): Hyperbolic function calculato
ID: 3792273 • Letter: 7
Question
78 full screen 4827813 view Problem 1 (35 points): Hyperbolic function calculator Write a C program that calculates the value of hyperbolic sine, hyperbolic cosine. and two other terms (without using the hyperbolic functions in the math.h library). Your program MUST contain the following user-defined functions 1) may cosh input: real-valued x output real-valued y where y cosho which is calculated using the following Taylor series expression y cosh(x) 1 Even though the actual Taylor series has an infinite number of terms, we will terminate the series at n 38. 2) my sinh input: real-valued x output real-valued y where y sinh(x) using the following y sinh (x) x Even though the actual Taylor series has an infinite number of terms, we will terminate the series at n 39. 3) double factorial(int n) double product 1.0; int i for (i 2; i n; i++) product product i return product; Note: The factorial function should be used in your my cosh and my sinh functionsExplanation / Answer
#include <math.h>
#include <stdio.h>
double my_coshx(double x){
double v = 1;
double y = 1;
for(int i = 1; i <= 19; ++i){
y = y*x*x/((2*i)*(2*i-1));
v += y;
}
return v;
}
double my_sinhx(double x){
double v = x;
double y = x;
for(int i = 1; i <= 19; ++i){
y = y*x*x/((2*i+1)*(2*i));
v += y;
}
return v;
}
void get_input(){
printf(" Option Function");
printf(" 1 sinh(x)");
printf(" 2 cosh(x)");
printf(" 3 sinh(2x)");
printf(" 4 cosh(2x)");
printf(" Enter 1-4:");
int d = -1;
scanf("%d", &d);
double x;
switch(d){
case 1:
printf("Enter value of x:");
scanf("%lf", &x);
printf(" sinh(%lf)=%lf",x, my_sinhx(x));
break;
case 2:
printf("Enter value of x:");
scanf("%lf", &x);
printf(" cosh(%lf)=%lf",x, my_coshx(x));
break;
case 3:
printf("Enter value of x:");
scanf("%lf", &x);
printf(" sinh(2*%lf)=%lf",x, 2*my_sinhx(x)*my_coshx(x));
break;
case 4:
printf("Enter value of x:");
scanf("%lf", &x);
double t = my_sinhx(x);
printf(" cosh(2*%lf)=%lf",x, 2*t*t+1);
break;
default:
return;
}
}
int main(){
char ch;
do{
get_input();
printf(" Do you want to continue (q to quit)?");
scanf("%c",&ch);
if(ch=='y') return 0;
}while(ch!='y');
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.