c语言小问题

[复制链接]
查看11 | 回复3 | 2009-2-10 16:03:50 | 显示全部楼层 |阅读模式
Problem Description
There are some students in a class, Can you help teacher find the highest student .
Input
There are some cases. The first line contains an integer t, indicate the cases; Each case have an integer n ( 1 ≤ n ≤ 100 ) , followed n students’ height.
Output
For each case output the highest height, the height to two decimal plases;
Sample Input
2
3 170.00 165.00 180.00
4 165.00 182.00 172.00 160.00
Sample Output
180.00
182.00
我的代码:#include
int main(void)
{
int i,n,t,j;
double k,max;
scanf("%d",&n);
for(i=0;imax)

max=k;
}
printf("%.2lf\n",max);
}
return 0;
}
为什么出不来答案?

回复

使用道具 举报

千问 | 2009-2-10 16:03:50 | 显示全部楼层
你的程序是没有任何问题的。 只是程序的输出不是按照你给出的那种方式,因为你是输入一行就输出一行。想所有输入完后再同时输出,你只需要用数组保存每行的max值即可。 你的程序改动如下,已在win-tc和Dev-c++下都调试通过。 #include #include int main(void) { int i,j,n,t; double k,max[80];/*注意这里,假定数据不超过80行,实际请更改*/ scanf("%d",&n); for(i=0;i<n;i++) { max=0; scanf("%d",&t); for(j=0;j<t;j++...
回复

使用道具 举报

千问 | 2009-2-10 16:03:50 | 显示全部楼层
每一个scanf都必须以一个回车作为输入结束,因此你在输入3 170.00 165.00 180.00 这一行时,只是在最后按了回车,这样并没有按照你所想的每个height都输入到了程序中,也就是说你把3 170.00 165.00 180.00 这行输完按了回车,你的程序scanf("%d",&t);for(j=0;j<t;j++)...
回复

使用道具 举报

千问 | 2009-2-10 16:03:50 | 显示全部楼层
什么出不来答案啊,不是能正常运行吗。能不能说清楚点啊...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行