永发信息网

C语言问题,帮我看看我的代码哪里错了 北大ACM1003- Hangover

答案:1  悬赏:0  手机版
解决时间 2021-04-08 23:53
题目:
Description
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n+ 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Sample Input
1.00
3.71
0.04
5.19
0.00
Sample Output
3 card(s)
61 card(s)
1 card(s)
273 card(s)

我的C程序如下:
#include
main()
{
int cards,i;
double longth,sum=0;
scanf("%lf",&longth);
while(cards!=0.00 && cards>=0.01 && cards<= 5.20){
cards=0,sum=0;
printf("longth=%lf\t",longth);
for(i = 2; sum sum += 1.00/i;
cards++;}
printf("%d card(s)\n", cards);
scanf("%lf",&longth);}
return 0;
}
最佳答案
一点小错误:
while(cards!=0.00 && cards>=0.01 && cards<= 5.20)
里面的card全改成longth就可以了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
写作表达(第29题,共40分)从下面两个文题中
亦加草字头是什么字
宝来手动变速箱
宜昌市伍家岗区环保局在哪里啊,我有事要去这
考研是数据结构容易还是通信原理,想自学,没
4个月的博美吃肠虫宁多久能吃饭
尿失禁怎么回事,打喷嚏时尿失禁如何治
手机电灯在哪里
三菱欧蓝德ex2010款3.0自动豪华版的,标价18.
有人想做影视资源代理吗?蚂蚁影视,专业团队
单选题地球绕太阳运动的轨道是一椭圆,当地球
48伏的电动车错用60伏的充电器电池外壳发烫还
想考教育学研究生但是不知道什么学校好考,只
您本月的主套餐包含流量200.00M,己使用111.3
拼音 K 共几画
推荐资讯
After a long walk, the old man felt very A
没天赋就不要学人画画,我为什么就是不明白
写洱海的唯美句子,赞美洱海的诗句
西安翻译学院QQ群 急啊 !!
华晨宝马发动机一汽大众发动机两款哪一款发动
武汉市汉正街市场管委会在哪里啊,我有事要去
有反应:X+H2SO4═ZnSO4+2Y,下面分析中不正
精工傢俱在什么地方啊,我要过去处理事情
宽带猫怎么连接路由器 电信商务领航(猫)。
如图甲所示:体温计的示数是________℃.图乙
With its moving story and the wonderful ac
安装塔吊怎样办理手续及检测手续?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?