#include<stdio.h>
float a[5][12];
int i, j;
int main()
{
void scores(int n, int m);
void average(int x, int y);
void class_average(int x, int y);
void fail(int x, int y);
for (i = 0; i <5; i++)
for (j = 0; j <11; j++)
scanf("%f", &a[i][j]); // 输入编号和成绩
printf("----- scores -----\n"); // 按顺序打印成绩
scores(5, 11);
for (i = 0; i < 5; i++)
for (j = 0; j < 11; j++)
{
if (j == 0)
printf("%d ", i+1);
else
if(j!=0||j!=10)
printf("%.1f ", a[i][j]);
if (j == 10)
printf("\n");
}
printf("----- average scores for students -----\n");
average(5, 12);
printf("----- average scores of courses -----\n");
class_average(5, 12);
printf("----- the number of fail on courses -----\n");
fail(5, 12);
return 0;
}
void swap(float* a, float* b)//从地址改变数值
{
float t;
t = *a;
*a = *b;
*b = t;
}
void scores(int n, int m)//排序成绩
{
void swap(float* a, float* b);
int k;
for (i = 0; i < n; i++)
{
for(j=i+1;j<n;j++)
if (a[i][0] > a[j][0])
{
swap(&a[i][0], &a[j][0]);
for (k = 1; k < m; k++)
swap(&a[i][k], &a[j][k]);
}
}
}
void average(int x, int y)//计算学生平均值
{
for (i = 1; i < 11; i++)
{
float sum = 0;
for (j = 0; j < 5; j++)
{
sum += a[j][i];
}
printf("%d %.1f\n", i, sum /5);
}
}
void class_average(int x, int y)//计算每门课的平均值
{
for (i = 0; i < 5; i++)
{
float sum = 0;
for (j = 1; j < 11; j++)
{
sum += a[i][j];
}
printf("%d %.1f\n", i + 1, sum / 10);
}
}
void fail(int x, int y)//不及格人数
{
for (i = 0; i < 5; i++)
{
int sum = 0;
for (j = 1; j < 11; j++)
{
if (a[i][j] < 60)
sum++;
}
printf("%d %d\n",i+1,sum);
}
}