69,373
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <math.h>
float countValue()
{
float x=0.0;
int n;
for(n=2;;n=n<<1)
{
if(cos(x)-x>1e-6)
{
x=x+1.0/n;
}
else if(x-cos(x)>1e-6)
{
x=x-1.0/n;
}
else
break;
}
return x;
}
int main(void)
{
printf("%f\n",countValue());
getch();
return 0;
}
#include <stdio.h>
#include <math.h>
float countValue()
{
float x0,x1=0.0;
while(1)
{
x0=x1;
x1=cos(x0);
if(fabs(x0-x1)<1e-6)
break;
}
return x1;
}
int main(void)
{
printf("%f\n",countValue());
getch();
return 0;
}