作业帮 > 综合 > 作业

利用公式求cos x的近似值,精确度为10-6

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/04 02:36:01
利用公式求cos x的近似值,精确度为10-6
#include
#define PI 3.14159
main()
{
int n,xx;
float t,sum,x;
printf("请输入弧度x=π/xx对应的分母值:");
scanf("%d",&xx);
x=PI/xx;
t=x;
n=0;
sum=0;
do
{sum+=t;
t=-t*x*x/(n+1)*(n+2);
n+=2;
}
while(fabs(t)>=1e-6);
printf("sin(PI/%d)=%f/n",xx,sum);
}
5-4.cpp
F:\C语言\5-4.cpp(7) :error C2065:'printf' :undeclared identifier
F:\C语言\5-4.cpp(8) :error C2065:'scanf' :undeclared identifier
F:\C语言\5-4.cpp(9) :warning C4244:'=' :conversion from 'double' to 'float',possible loss of data
F:\C语言\5-4.cpp(20) :warning C4508:'main' :function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
你没有引入输入头文件
#include "iostream"
using namespace std;