C学生成绩统计
程序员文章站
2024-01-16 10:43:28
...
输入10个学生的成绩,输出平均分,最高分,最低分
输入一个分数,输出多少学生比这个分数高
#include <stdio.h>
void main()
{
int grade[10],grade0[10];
int i, maxGrade, minGrade,tmp,x,m=0;
double avg,sum=0;
printf("输入10个学生的成绩:\n");
for (i = 0; i < 10; i++)
{
scanf("%d", &grade[i]);
grade0[i] = grade[i];
}
for (int i= 0; i < 9; i++)
for (int j = 0; j < 9; j++)
if (grade[j] > grade[j + 1]) {
tmp = grade[j];
grade[j] = grade[j + 1];
grade[j + 1] = tmp;
}
for (i = 0; i < 10; i++) {
if (grade0[i] == grade[0]) minGrade = i + 1;
if (grade0[i] == grade[9]) maxGrade = i + 1;
}
for (i = 0; i < 10; i++)
sum += grade[i];
avg = sum / 10;
printf("average=%.1lf ", avg);
printf("max=%d ", maxGrade);
printf("min=%d\n", minGrade);
printf("请输入一个分数:");
scanf("%d", &x);
for (i = 0; i < 10; i++)
if (grade[i] >= x) m++;
printf("%d students", m);
}
上一篇: matplotlib常用函数
下一篇: c++ 学生成绩统计(10)