运用数学函数math算的sin的值
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#define eps 1e-6
int main()
{
int n = 1; float x;
double fz, fm = 1, sinx;
printf("输入x的值:");
scanf("%f",&x);
fz = x; sinx = x;
do
{
n = n + 1;
fz = -fz * x * x;
fm = fm * (2 * n - 2) * (2 * n - 1);
sinx = sinx + fz / fm;
} while (fabs(fz / fm) > eps);
printf("sin(%f)=%0.6f\n", x, sinx);
printf("sin(%f)=%0.6f\n", x, sin(x));
return 0;
}
[代码未核查]
代码运行结构
代码下载
Views: 109