大佬,我这个程序运行出来是0.98,请问问题出在哪儿了呢?
/*Purpose:.设计二个子函数分别计算sinX和cosX, 要求精度为1.0e-6。在主函数中调用函数求(sin30°+ cos60°),输出结果*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.1415926
double fun1(int);
double fun2(int);
int main(void)
{
int x = 30, y = 60;
double a, b;
a = fun1(30);
b = fun2(60);
printf("sin30°+ cos60° = %.2lf\n", a + b);
system("pause");
return 0;
}
double fun1(int x)
{
double i, y, t, fsin;
i = 1.0;
y = x * PI / 180.0;
t = y;
fsin = 0.0;
while(fabs(t) > 1.0e-6)
{
fsin += t;
i += 2.0;
t = -y * y * t / (i * (i-1.0));
}
return fsin;
}
double fun2(int x)
{
double i, y, t, fcos;
i = 0.0;
y = x * PI / 180.0;
t = y;
fcos = 1.0;
while(fabs(t) > 1.0e-6)
{
i += 2.0;
t = -y * y * t / (i * (i-1.0));
fcos += t;
}
return fcos;
}