༄༊࿆水下月ོྂཾ࿆࿐ 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日