鱼C论坛

 找回密码
 立即注册
查看: 2509|回复: 1

c语言 成绩统计 结果四舍五入

[复制链接]
发表于 2021-3-30 21:28:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#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;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-30 23:12:11 | 显示全部楼层
  1. #include <stdio.h>
  2. int main(void)
  3. {
  4.         int i , n , x , jx , yx                                     ;  //n表示考试人数,jx表示及格率,yx表示优秀率
  5.         scanf("%d" , & n)                                           ;
  6.         for(i = yx = jx = 0 ; i < n ; i ++) {
  7.                 scanf("%d" , & x)                                   ;
  8.                 if(x > 60) jx ++                                    ;
  9.                 if(x >= 85) yx ++                                   ;
  10.         }
  11.         printf("%.0f%%\n%.0f%%\n" , jx * 100.0 / n, yx * 100.0 / n) ;
  12. }
复制代码

        编译、运行实况
  1. D:\00.Excise\C>g++ -o x x.c

  2. D:\00.Excise\C>x
  3. 8
  4. 40
  5. 50
  6. 60
  7. 70
  8. 80
  9. 90
  10. 93
  11. 95
  12. 63%
  13. 38%

  14. D:\00.Excise\C>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-15 15:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表