利用公式求cos x的近似值,精确度为10-6 #include#define PI 3.14159main(){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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/08 16:41:17
利用公式求cos x的近似值,精确度为10-6 #include#define PI 3.14159main(){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
利用公式求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 时出错.
利用公式求cos x的近似值,精确度为10-6 #include#define PI 3.14159main(){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
你没有引入输入头文件
#include "iostream"
using namespace std;