zoukankan      html  css  js  c++  java
  • 数组练习

    在一个长度为10的整型数组里面,保存了班级10个学生的考试成绩。要求编写5个函数,分别实现计算考试的总分,最高分,最低分,平均分和考试成绩降序排序。

    #include <stdio.h>
    #include <string.h>
    int totalScore(int score[])
    {
    int sum=0,i;
    for(i=0;i<=9;i++)
    {
    sum += score[i];
    }
    return sum;
    }
    int maxScore(int score[])
    {
    int i,max=0;
    for(i=0;i<=9;i++)
    {
    if(score[i]>max)
    {max = score[i];}
    }
    return max;
    }
    int minScore(int score[])
    {
    int i,min=100;
    for(i=0;i<=9;i++)
    {
    if(score[i]<min)
    {min = score[i];}
    }
    return min;
    }
    float averageScore(int score[])
    {
    return totalScore(score)/10;
    }
    void sortScore(int score[])
    {
    int i,j,temp;
    for(i=0;i<=8;i++)
    {
    for(j=0;j<=8;j++)
    {
    if(score[j]<score[j + 1])
    {
    temp = score[j];
    score[j] = score[j + 1];
    score[j + 1] = temp;
    }
    }
    }
    }
    int main()
    {
    int i;
    int score[10]={67,98,75,63,82,79,81,91,66,84};
    printf("%d ",totalScore(score));
    printf("%d ",maxScore(score));
    printf("%d ",minScore(score));
    printf("%1.1f ",averageScore(score));
    sortScore(score);
    for(i=0;i<=9;i++)
    {
    printf("%d ",score[i]);
    }
    return 0;
    }

     
  • 相关阅读:
    弹性盒子
    bzoj4237 稻草人
    bzoj2654 tree
    bzoj4813 [Cqoi2017]小Q的棋盘
    bzoj1014 [JSOI2008]火星人
    bzoj3242 [Noi2013]快餐店
    bzoj4025 二分图
    bzoj3237 [Ahoi2013]连通图
    bzoj3244 [Noi2013]树的计数
    bzoj2431 [HAOI2009]逆序对数列
  • 原文地址:https://www.cnblogs.com/xiaodi914/p/5361528.html
Copyright © 2011-2022 走看看