Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <math.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- double power (int base, int n){
- int p,i;
- for (i = 1; i<n+1; i++){
- p = p*i;
- }
- return p;
- }
- double degrees_to_rad (double x){
- x = x * M_PI/180;
- return x;
- }
- double absolute(double paragontas){
- return paragontas = sqrt(power(paragontas,2));
- }
- int main(int argc, char *argv[]) {
- int i=1,l=1;
- double xdeg,xrad,sin1,sum=0,check;
- printf("Give me the x in degrees:");
- scanf("%lf",&xdeg);
- xrad = degrees_to_rad(xdeg);
- do{
- if(i==1)
- {
- sin1=power(xrad,i)/i;
- }
- else
- {
- sin1=power(xrad,i)/(i*(i-1));
- l=l*(-1);
- }
- check = absolute(sin1 - power(xrad,i-1)/((i-1)*(i-2)));
- if ( check >= 0.000001)
- {
- sum = sum + l*sin1;
- }
- i+=2;
- } while ( check >= 0.000001);
- printf("The result using taylor series is --> %lf \n"
- "The result using c function sin(x) is ---> %lf",sum,sin(xrad));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement