利用泰勒级数计算sinx的值(递归方法)

 1 #include<stdio.h>
 2 #include<math.h>
 3 double mypow(double x,int i)
 4 {
 5     if (i==1||i==0) return x;
 6     return x*mypow(x,i-1);
 7 }
 8 double orz (int i)
 9 {
10     if (i==1||i==0) return 1;
11     return i*orz(i-1);
12 }
13 int main()
14 {
15     int i=1,count=0;
16     double x,sinx=0;
17     printf("Input x:\n");
18     scanf("%lf",&x);
19     do
20     {
21         sinx=sinx+pow(-1,count)*mypow(x,i)/orz(i);
22         i+=2;
23         count++;
24     }while(fabs(mypow(x,i)/orz(i)>1e-5));
25     count++;
26     printf("sin(x)=%.3f,count=%d\n",sinx,count);
27     return 0;
28 }

 

相关文章:

  • 2022-12-23
  • 2022-01-23
  • 2021-10-16
  • 2021-12-19
  • 2022-01-14
  • 2021-10-31
  • 2021-12-19
猜你喜欢
  • 2022-01-18
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
相关资源
相似解决方案