// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
int sumScore(int score[],int arrLen)
{
int sumS = 0;
for (int i = 0; i <arrLen;i++)
{
sumS += score[i];
}
;
return sumS;
}
int maxScore(int score[], int arrLen)
{
int maxScore = 0;
for (int i = 0; i < arrLen - 1; i++)
{
if (score[i] > score[i + 1])
{
int temp = score[i];
score[i] = score[i + 1];
score[i + 1] = temp;
maxScore = score[arrLen - 1];
}
}
printf("考试的最高分为:%d \n", maxScore);
return 0;
}
int mixScore(int score[], int arrLen)
{
int mixScore = 0;
for (int i = 0; i < arrLen-1; i++)
{
if (score[i] < score[i + 1])
{
int temp = score[i];
score[i] = score[i + 1];
score[i + 1] = temp;
mixScore = score[arrLen - 1];
}
}
printf("考试的最低分为:%d \n",mixScore);
return 0;
}
float averageScore(int score[], float arrLen, float sumS)
{
float averageS;
averageS = sumS / arrLen;
printf("考试的平均分为:%.1f \n", averageS);
return 0;
}
int dSortScore(int score[], int arrLen)
{
for (int i = 0; i < arrLen; i++) //降序排列
{
for (int j = 0; j < arrLen -1; j++)
{
if (score[i] > score[j])
{
int temp = score[i];
score[i] = score[j];
score[j] = temp;
}
}
}
printf("考试成绩降序排序如下: \n");
for (int k = 0; k < arrLen; k++)
{
printf("%d \n", score[k]);
}
return 0;
}
int main()
{
int score[] = { 67,98,75,63,82,79,81,91,66,84 };
int arrLen = sizeof(score) / sizeof(int);
printf("考试的总分为:%d \n", sumScore(score, arrLen));//没直接在函数里写死输出是为了方便平均数函数的调用。
maxScore(score, arrLen);
mixScore(score, arrLen);
averageScore(score,arrLen, sumScore(score, arrLen));
dSortScore(score, arrLen);
getchar();
return 0;
}