༄༊࿆水下月ོྂཾ࿆࿐ 2022-12-13 17:59 采纳率: 98%
浏览 56
已结题

计算学生等级:针对每门课程,根据学生的积分,计算相应等级。

img


以下是我的算法

#include <stdio.h>
#include <math.h>
int main()
{
    double level;
    double score;
    printf("输入分数:");
    scanf("%lf",&score);
    level=log10(score+1);
    printf("等级为:%.0lf",level);
    return 0;
}

由于计算机设定的规定(四舍五入)对等级不知道怎么计算
以下是我的算法的运行结果:

img

img

img

img


在分数为1,2是不符合等级计算法则
应该怎么修改?

  • 写回答

1条回答 默认 最新

  • |__WhoAmI__| 2022-12-13 22:47
    关注
    #include <stdio.h>
    #include <math.h>
    
    int get_grade(int score) {
      // If the score is between 1 and 8, the grade will be 1
      if (score >= 1 && score <= 8) {
        return 1;
      }
    
      // Otherwise, calculate the grade using the formula:
      // grade = [log10(score + 1)]
      return (int)log10(score + 1);
    }
    
    int main() {
      // Prompt the user for a score
      printf("Enter a score: ");
      int score;
      scanf("%d", &score);
    
      // Calculate the grade
      int grade = get_grade(score);
    
      // Print the result
      printf("Grade: %d\n", grade);
    
      return 0;
    }
    

    这次可以了,我都运行试过了,望采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月13日
  • 已采纳回答 12月13日
  • 创建了问题 12月13日

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)