Writing C code for sin(x) using taylor series

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Stone
    New Member
    • Feb 2011
    • 1

    Writing C code for sin(x) using taylor series

    I am trying to write C code for sin(x) using the first 5 terms of the taylor series. I am new to programming and am not allowed to use loops. I don't have much yet, but what I have so far is:

    Code:
    /* solution to Taylor Series approximation of sin(x) */
    #include <stdio.h>
    #define PI 3.1416f
    
    int main ()
    {
    float x_deg;
    float x;
    float sinx;
    
    /*enter the angle "x_deg in degrees"*/
    printf ("Enter x_deg:");
    scanf ("%f, %x_deg);
    
    x=x_deg*PI/180;
    I am not really sure where to go from here. I am a little confused about how to implement the taylor series to calculate sin(x). Any help would be appreciated, thanks.
    Last edited by acoder; Feb 4 '11, 02:08 PM. Reason: Added [code] tags. Please use them when posting code.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Perhaps you had better explain how the Taylor series is calculated, or rather what it is you want to calculate. We ar code gurus not maths gurus :D

    You seem to have used the type float in your program but normally we would advise anyone using floating point types to use double unless they have a good and communicable reason why they need to use float.

    Comment

    Working...