全部问题 > 当前问题

麻烦老师看看代码哪里有问题。

QHG`%IJS87}15K{)OPBW3J8.png

软肋, 2015-8-10 19:47:31

共 4 个回答

浅↑夏忆↓瞬 2015-8-10 20:02:22

你可以这样改

#include <stdio.h>
float fun ( float  h )
{
int n=(int)(h*100+0.5);
return n/100;
}

软肋, 2015-8-10 21:09:46

回复 浅↑夏忆↓瞬:这样运行结果是不对的。

祁老师 2015-8-11 09:54:11

int需要加括号

浅↑夏忆↓瞬 2015-8-11 10:21:40

#include <stdio.h>
float fun ( float  h )
{
int n=(int)(h*100+0.5);
return n/100.0;
}

sorry,打漏了,上面是一种方法,该题给的答案也可以这样写

float fun (float h )
{
 long t;
 t=(h*1000+5)/10;
 return (float)t/100;
}

这两种方法都是对的

问题来自: 编程题真题