首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。 例如,当给指定精度的变量eps输入0.0005时,应输出Pi=3.140
使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。 例如,当给指定精度的变量eps输入0.0005时,应输出Pi=3.140
admin
2018-10-21
29
问题
使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。
例如,当给指定精度的变量eps输入0.0005时,应输出Pi=3.140578。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<stdio.h>
#include<math.h>
double fun(double eps)
{
double s,t;int n=1;
s=0.0;
/*********found*********/
t=0;
while(t>eps)
{
s+=t;
t=t*n/(2*n+1);
n++;
}
/*********found*********/
return(s);
}
void main()
{
double x;
printf("\nPlease enter a precision:");
Scanf("%lf",&x);
printf("\nPi=%lf\n",fun(x));
}
选项
答案
(1)t=1.0; (2)return(s*2);
解析
该题中,首先检查变量数据类型前后是否一致,因为变量t定义为double型,所以赋值时要赋以实型数值。return(s)是一个数学错误,应该返回return(s*2);。
转载请注明原文地址:https://jikaoti.com/ti/Qoa0FFFM
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下关于字符串的叙述中正确的是()。
下列程序的运行结果是()。#include<stdio.h>main(){inta=0,b=4,c=0,d=10,x;if(a)d=d-10;else
设“intx=2,y=1;”,则表达式(!x‖y--)的值是()。
设x,y和z都是血型变量,且x=3,y=4,z=5,则下面表达式中,值为0的表达式是
下列选项中不符合良好程序设计风格的是______。
有以下程序main(){union{unsignedintn;unsignedcharc;}ul;u1.C=’A’;pfintf("%c\n",u1.n);
执行以下程序段的输出结果是()。intm=0x12,n=0x12;m=m-n;printf("%X\n",m);
下列关于“数据库系统(DBS)”的叙述中,正确的一条是______。
下面函数用来求两个单精度数之和,并通过形参将结果传回,请填空。Voidsub(floatx,noaty,【】z){【】=x+y;}
以下程序运行后的输出结果是______________。#definePower2(x)x*xmain(){inti=6j=8;printf(“%d﹨n”,Power2(i+j));}
随机试题
新课程从“文本课程”走向“体验课程”,教师由教学中的主角转向“平等中的首席”。()
某2型糖尿病患者,50岁,实际体重超过标准体重25%,其饮食总热量应
属于藏药药味的是()。
高血压联合用药的原则应是
某企业向银行借款300万元,借款年利率为10%,筹资费费率为2%,所得税税率为33%,则其借款成本率为( )。
在借贷记账法下,借表示增加,贷表示减少。()
中华民族的母亲河是()。
从众的类型有()
某社区属于老的居住小区,没有实行物业管理,基础设施较差,老年人居住比例较高。居民在小区散步没有坐下来休息的地方,社区的老年人和他们的子女经常到社区居委会反映这个问题,建议修建一些路椅。为此社区居委会草拟了修建社区路椅的初步方案,召开社区居民代表会议讨论,并
•Readthearticlebelowabouttheimportanceofwritingjobdescriptions.•ChoosethebestwordtofilleachgapfromA,B,
最新回复
(
0
)