# 泰勒级数展开近似sin(x)的值 C语言(C language for approximating the value of sin (x) by Taylor series expansion)-c语言

## 泰勒级数展开近似sin(x)的值 C语言(C language for approximating the value of sin (x) by Taylor series expansion)

0.5233结尾无空行

0.4997结尾无空行

code：

`````` 1 #include<stdio.h>
2 #include<math.h>
3 int main()
4 {
5     double a;
6     scanf("%lf",&a);
7
8
9     double zi=a,mu=1;//zi指的是分子 mu指的是分母
10     double xiang=zi/mu;
11     double sin=xiang;
12     int j=1;//统计第几项
13
14     for(int i=3;;i+=2)
15     {
16         if(fabs(xiang)<1e-5) break;//注意当有一项满足时跳出
17
18         j++;
19         zi=pow(a,i);
20         mu=i*(i-1)*mu;
21         xiang=zi/mu;
22
23         if(j%2==0)//通过观察可知奇数项为正 偶数项为负
24         xiang=-xiang;
25
26         sin+=xiang;//sin的值
27     }
28     printf("%.4lf",sin);
29     return 0;
30 }``````

————————

Write a program, input x from the keyboard, and use the power series expansion to calculate the approximate value of sin (x). It is required that the absolute value error of a certain item is less than 10 ^ – 5. The formula is as follows:

Method tip: for similar sequence summation problems, the key is to abstract the general formula of item I and add the derived general item I to sum until the absolute value of item I is less than 1e-5. In addition, pay attention to the processing of parity symbols.

Input format: enter X.

Output format: approximation result of sin (x).

Input example: a set of inputs is given here.

For example:

0.5233 no blank line at the end

Output example: keep 4 decimal places.

For example:

0.4997 no blank line at the end

code：

`````` 1 #include<stdio.h>
2 #include<math.h>
3 int main()
4 {
5     double a;
6     scanf("%lf",&a);
7
8
9     double zi=a,mu=1;//zi指的是分子 mu指的是分母
10     double xiang=zi/mu;
11     double sin=xiang;
12     int j=1;//统计第几项
13
14     for(int i=3;;i+=2)
15     {
16         if(fabs(xiang)<1e-5) break;//注意当有一项满足时跳出
17
18         j++;
19         zi=pow(a,i);
20         mu=i*(i-1)*mu;
21         xiang=zi/mu;
22
23         if(j%2==0)//通过观察可知奇数项为正 偶数项为负
24         xiang=-xiang;
25
26         sin+=xiang;//sin的值
27     }
28     printf("%.4lf",sin);
29     return 0;
30 }``````

This article focuses on learning from each other. If there is anything wrong, please let me know. Thank you