我是新手 请问农村阴宅风水谢谢我如何加入你们这个团队 谢谢

欢迎加入我们,一同切磋技术。 &
用户名: &&&
密 码: &
共有 6269 人关注过本帖
标题:我是新手,请问怎样取整数,去掉小数点后面的数。谢谢!
等 级:新手上路
帖 子:68
结帖率:50%
&&已结贴√
&&问题点数:20&&回复次数:16&&&
我是新手,请问怎样取整数,去掉小数点后面的数。谢谢!
写一个程序,读入一个球体的半径,计算出它的表面积和体积,然后打印
他们向下调整至最接近的整数。
定义一个常数,称为PI,并给它值3.14公式中使用的:
的表面积是:314
体积为:523
#include &iostream&
int main()
&&& double surfaceA
&&& double PI;
&&& cout && &Program to compute and output the volume and surface area of a sphere& &&
&&&&&cout &&&Input radius:&&&
&&& cin &&
&&& PI&&= 3.14;
&&& surfaceArea=4* PI * radius *
&&& volume = a / b * PI * radius * radius *
&&& cout && &Radius is: & && radius &&
&&& cout && &The surface area is:& && surfaceArea &&
&&& cout && &The volume is: & && volume &&
&&& return 0;
搜索更多相关主题的帖子:
等 级:版主
威 望:200
帖 子:4765
专家分:25801
你想要的是&math.h&中的 double floor( double x ); 吗?
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2779
专家分:6060
想保留几位小数就扩大10的多少倍取整
我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给***,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
等 级:新手上路
帖 子:68
谢谢你们那么快的回复!
你看我的程序那里有错误,我刚开始学。
我还没学到“&math.h&中的 double floor( double x ); ”这里。2位
我不要小数位的,只要整数输出
什么叫calculates its surface area and volume then prints them rounded down to the nearest whole number?--这是题目要求。
请帮我看看 ,谢谢!
等 级:论坛游民
帖 子:26
专家分:43
这还不简单,直接定义一个整数接受结果的值。直接输出就OK了!会有警告,但不会有问题。
例如:double i =3.13;
&&& int m =
&&& 那么m的值就是3了
等 级:论坛游民
帖 子:26
专家分:43
回复 5楼 羽VS翼
或者直接强转为整形:(int&)double
等 级:版主
威 望:200
帖 子:4765
专家分:25801
以下是引用SwanK在 14:37:23的发言:
谢谢你们那么快的回复!
你看我的程序那里有错误,我刚开始学。
我还没学到“中的 double floor( double x ); ”这里。2位
我不要小数位的,只要整数输出
什么叫calculates its surface area and volume then prints them rounded down to the nearest whole number?--这是题目要求。
请帮我看看 ,谢谢!我还没学到“&math.h&中的 double floor( double x ); ”这里
------ 你学的是语法,而这是C/C++标准库中的函数。除了这个标准函数外,我想不到你还能用其他什么方法完成题目要求的功能。
什么叫calculates its surface area and volume then prints them rounded down to the nearest whole number?
------ 这句洋文还简单呀:计算它的表面积和体积,然后向下圆整到最近的整数后,打印出它们。
等 级:论坛游民
帖 子:52
专家分:37
强制类型转换啊,还有那个PI常量的不是这样定义的吧
等 级:新手上路
帖 子:68
感谢你们的回帖。我改了了一下。你们看怎样?请指出错误!谢谢!
#include &iostream&
&//name constants
&&&const double PI=3.14;
&&&const int top=4;
&&&const int base=3;
int main()
&&// declare variable
&&& double surfaceA
&&&//statements:step 1 - step7
&&& cout && &Program to compute and output the volume and surface area of a sphere& &&
&&&&&cout &&&Enter&&radius:&&&&&&&&&&&&&&&&&&&&&&&& //step1
&&&&&cin &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//step2
&&&&&surfaceArea=4* PI * radius *&&&&&&&&&&&&&&&&&&//step3
&&&&&volume = a / b * PI * radius * radius *&&&&&&&&//step4
&&&&&round(volume)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//step5&&&
&&&&&cout && &Radius is: & && radius &&&&&&&&&&&&&&&&//step5
&&&&&cout && &The surface area is:& && surfaceArea &&//step6
&&&&&cout && &The volume is: & && volume &&&&&&&&&&& //step7&&
&&& return 0;
等 级:新手上路
帖 子:68
回复 9楼 SwanK
错了一点:
以上要改这2处。忘记了。
版权所有,并保留所有权利。
Powered by , Processed in 0.078181 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved你好,我想加入你们团队,谢谢_百度拇指医生
&&&网友互助
?你好,我想加入你们团队,谢谢
拇指医生提醒您:该问题下为网友贡献,仅供参考。
请你自己加入,我即可审批。
向医生提问
完善患者资料:*性别:
为您推荐:
* 百度拇指医生解答内容由公立医院医生提供,不代表百度立场。
* 由于网上问答无法全面了解具体情况,回答仅供参考,如有必要建议您及时当面咨询医生

参考资料

 

随机推荐