U_touchable @ 2020-11-22 09:48:46
这里是代码
#include<stdio.h>
int main(void){
int n, min, max;
int sum = 0;
scanf("%d",&n);
int score[n];
int i = 0;
for(i = 0; i < n; i ++){
scanf("%d",& score[i]);
}
max = min = score[0];
for(i = 0; i < n; i ++){
if(max < score[i]){
max = score[i];
}
if(min > score[i]){
min = score[i];
}
sum += score[i];
}
// printf("%d %d %d\n",sum, max, min);
printf("%.2f", (sum - max - min)/(n - 2));
return 0;
}
前面的几个值都是正确的,但是输出一直是0.00 泪了
by 渡鸦2007 @ 2020-11-22 09:51:51
@U_touchable
你变量类型不对
改成printf("%.2f", double(sum - max - min)/(n - 2));
by 渡鸦2007 @ 2020-11-22 09:52:52
@U_touchable
%f输出浮点数,而你后面变量都是int,相除还是int类型,%f不能接受
by U_touchable @ 2020-11-22 09:54:15
@fqyz_wyc 好的好的,谢谢!!
by Dimly_dust @ 2020-11-22 09:55:37
@U_touchable 把最后的输出写成这样既可:
printf("%.2f", (sum*(1.0) - max - min)/(n - 2));
by U_touchable @ 2020-11-22 09:58:13
@Dimly_dust 好滴√ 谢谢!