c语言 成绩统计 结果四舍五入
#include <stdio.h>main()
{
int n,jx=0,yx=0;//n表示考试人数,jx表示及格率,yx表示优秀率
scanf("%d",&n);
while(n--)
{
int x;//x接收输入的数据
scanf("%d",&x);
if(x>60)
{
jx++;
}
if(x>=85)
{
yx++;
}
}
printf("%d %d\n",jx,yx);
double Yx;
Yx=yx*1.0/(n*1.0);
printf("%f\n",Yx);
printf("%d\n",yx);
double Jx;
Jx=(jx*1.0)/(n*1.0);
//printf("%lf%\n%lf%\n",Yx,Jx);
//Yx=-Yx;
//Jx=-Jx;
int ans_jx = int(Jx * 1000 + 5) / 100;
int ans_yx = int(Yx * 1000 + 5) / 100;
printf("%d%%\n%d%%\n", ans_jx, ans_yx);
return 0;
} #include <stdio.h>
int main(void)
{
int i , n , x , jx , yx ;//n表示考试人数,jx表示及格率,yx表示优秀率
scanf("%d" , & n) ;
for(i = yx = jx = 0 ; i < n ; i ++) {
scanf("%d" , & x) ;
if(x > 60) jx ++ ;
if(x >= 85) yx ++ ;
}
printf("%.0f%%\n%.0f%%\n" , jx * 100.0 / n, yx * 100.0 / n) ;
}
编译、运行实况
D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
8
40
50
60
70
80
90
93
95
63%
38%
D:\00.Excise\C>
页:
[1]