题解 | #统计成绩#

统计成绩

https://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba

#include <stdio.h>
void bubble_sort(double *arr, int len);
int main(void)
{
    int subject = 0;
    double sum = 0;
    scanf("%d", &subject);         // The length of array
    double subject_score[subject]; // Initialize the array

    for (int i = 0; i < subject; i++)
    {
        scanf("%lf", &subject_score[i]);
        sum += subject_score[i];
    }

    bubble_sort(subject_score, subject);
    printf("%.2lf %.2lf %.2lf\n", subject_score[0], subject_score[subject - 1], sum / subject);
    return 0;
}

// @brief bubble sort(from min to max)
void bubble_sort(double *arr, int len)
{
    double temp_val = 0;
    for (int i = 0; i < len - 1; i++)
    {
        for (int j = 0; j < len - i - 1; j++)
        {
            if (arr[j] > arr[j + 1])
            {
                temp_val = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp_val;
            }
        }
    }
}

全部评论

相关推荐

05-12 17:28
已编辑
门头沟学院 硬件开发
ldf李鑫:不说公司名祝你以后天天遇到这样的公司
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务