Compute the sine of an angle x using the infinite series expansion. - C Data Type

C examples for Data Type:float

Introduction

The formula of the infinite series expansion is given here:

sin x = x - x3/3! + x5/5! - x7/7! + ...

Here, x is in radians, and it takes values in the range -1 <= x <= 1.

Demo Code

#include <stdio.h>

int main()// w ww.  j ava  2s . c o m
{
     double sine, term, x = 0.7, z;
     int k  = 1;
     char ch;
    
     term = x;
     sine = x;
     z = x * x;
    
     for (int i = 1; i <= 10; i++) {
       k = k + 2;
       term = -term * z /(k * (k - 1));
       sine = sine + term;
     }
    
     printf("Sine of %lf is %lf\n", x, sine);
     return(0);
}

Result


Related Tutorials