
题目
解决代码及点评
/* 计算Yn的值,直到|Yn - Yn-1|<10-6为止,并打印出此时共作了多少次COS计算。
提示:Yn+1=COS(Yn),故本题适用于使用迭代法。 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int f(double m,int count)
{
if (abs(cos(m) - m) < pow(10.0,-6))
{
return count + 1;
}
else
{
return f(cos(m),++count);
} }
void main()
{
int n = f(1,0);
printf("n = %d\n",n);
system("pause");
}
代码编译以及运行
由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:
1)新建工程
2)选择工程
3)创建完工程如下图:
4)增加文件,右键点击项目
5)在弹出菜单里做以下选择
6)添加文件
7)拷贝代码与运行
程序运行结果
代码下载
http://download.****.net/detail/yincheng01/6681845
解压密码:c.itcast.cn