基于visual Studio2013解决C语言竞赛题之0419误差控制

来源:互联网 发布:幸运28加拿大外围源码 编辑:程序博客网 时间:2024/05/22 14:59





题目


解决代码及点评

/************************************************************************//* 19.在一个程序中计算出给定误差小于0.1,0.01,0.001,0.0001,0.00001 时,下式的值:*//************************************************************************/#include <stdio.h>#include <stdlib.h>void Go19(float num){float n=1;float J1=2*n*(2*n+2)/(2*n+1)/(2*n+1);float J2=2*n*(2*n+2)/(2*n+1)/(2*n+1);do {n=n+1;J1=J2;J2*=2*n*(2*n+2)/(2*n+1)/(2*n+1);} while (J1-J2>num);printf("结果是%f\n",J1);}void main(){Go19(0.1);Go19(0.01);Go19(0.001);Go19(0.0001);Go19(0.00001);system("pause");}



代码下载及其运行

代码下载链接:

http://download.csdn.net/detail/yincheng01/6641021

解压密码为c.itcast.cn


下载解压后用VS2013打开工程文件

点击 “本地Windows调试器” 执行


程序运行结果