Solving the polynomial of the approximate value of sin (x) of sine function

Source: Internet
Author: User
Tags sin
/* The polynomial formula for the approximate value of the sine sin (x) is known to be:
sin (x) = x-x3/3! + x5/5!-x7/7!+ ... + ( -1) n x2n+1/(2n+1)!  + ... 
*
/#include <stdio.h>
#include <math.h> 
void Main ()
{ 
	int  i; 
	float  x,sum,a,b;  Sum represents and, a is a molecule, B is the denominator 
	char s; 
	printf ("Please input X"); 
	scanf ("%f", &x); 
	S=1; 
	sum=0; 
	a=x;     The denominator assigns the initial value
	b=1;     The numerator assigns the initial value for 
	(i=1;a/b>=1e-6;i++) 
	{  
		sum=sum+s*a/b;    Accumulate a  
	    a=a*x*x;     Seek the next molecule  
	    b=b*2*i* (2*i+1);   Seek the next denominator  
	    s*=-1; 
	}  
	printf ("sum=%f\n", sum);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.