Question
PLEASE WRITE IN C AND ONLY USE STDIO.H, NOT MATH.H Write a function, cos(x), using the taylor expansion and use it in a program to
PLEASE WRITE IN C AND ONLY USE STDIO.H, NOT MATH.H
Write a function, cos(x), using the taylor expansion and use it in a program to find the cosine of values read until EOF.
Here you will be writing a function:
double cos(float);
to compute the cos of an angle (given in radians) using the Taylor series shown. Your function should find the value of the cos for ANY angle (preferred) or at least angles up to 2 PI (Hint: if you can do the later, the former should be easy) to a precision of 4 decimal places (within 0.00005). You should put the function cos() in the file called trig.c. You can use the function pos_power() in your exponent.c from Lab 6 and Hw 4, and you should write functions for factorial() and close_enough() in the file called util.c. This last function is given two doubles and returns true if they are within 0.00005 of each other. You can put any other functions you may want in util.c as well. You will need to provide your own .h files for each of these .c files. You should also write a simple test driver to exercise your function in the file driver1.c. You should update the makefile to compile and link driver1.c, trig.c, util.c and exponent.c when you type
make trig
and create the executable called trig.
NOT SURE IF THE BELOW CODES ARE FULLY RELEVENT
Exponent.h
float pos_power(float base, int exponent);
double cos(float)
Exponent.c
#include"exponent.h"
{ int x, y; i=1; ans=1;
while(i<=y) { ans=ans*x; i=i+1; }
return 0;
}
UTIL.C
float factorial(int i) { int i; for(i = 2; i <= 2 * acc; i += 2) i* = 1; return i; }
float close_enough(float a, float b) { float c=a-b; if(c < 0) { c = c * (-1); } if(c <= 0.00005) return 1; else return 0;
}
Step 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