求看一下哪里错了
#include <stdio.h>
#include <math.h>
double Fact(double n);
double pow_n(double x,double n);
void sinx(double x);
int main()
{
double x;
printf("Input x:\n");
scanf("%lf",&x);
sinx(x);
return 0;
}
//计算sin
void sinx(double x) {
int sign = -1;//正负号标识符
int count=0;//用于计数
double fraction,sinx=x;
do{
int i=1;
i = i+2;
sign = -sign;//正负号切换
fraction = pow_n(x, i) / Fact(i);//计算每个分母
fraction = fraction * sign;
count++; //计数
sinx=sinx + fraction;
}while(fabs(fraction) < 1e-5);
printf("sin(x)=%.3f,count=%d\n", sinx, count);
}
//阶乘
double Fact(double n)
{
int result = 1;
for (int i = 1; i <= n; i++)
{
result = result * i;
}
return result;
}
////自定义pow函数x的n次幂
double pow_n(double x,double n)
{
double m=1;
if(n==0)
return 1;
else {
for (int i = 1; i <= n; i++) {
m = m * x;
}
return m;
}
}