#include<stdio.h>
#include<string.h>
void arr_student(int a[10][5])
{
float sum = 0;
int i, j;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 5; j++)
{
sum += a[i][j];
}
sum /= 5;
printf("学生%d的平均为%f\n", i + 1, sum);
sum = 0;
}
}
void arr_lesson(int a[10][5])
{
char m_class[5] = { 'A','B','C','D','E' };
float sum = 0;
int i, j;
for (j = 0; j < 5; j++)
{
for (i = 0; i < 10; i++)
{
sum += a[i][j];
}
sum /= 10;
printf("lesson%c的平均分为%f\n", m_class[j], sum);
sum = 0;
}
}
void goodstudent(int a[10][5])
{
char m_class[5] = { 'A','B','C','D','E' };
int i, j, t, k = 0, l = 0;//定义所需函数
t = a[0][0];
for (i = 0; i < 10; i++)//用for循环来逐个比较
{
for (j = 0; j < 5; j++)
{
if (t < a[i][j])
{
t = a[i][j];
k = i;//第几个学生
l = j;//哪门科目
}
}
}
printf("最高分数是%d,他是第%d个学生,他的科目是%c\n", t, k + 1, m_class[l]);
}
int main()
{
//
//int a[10][5]=
//{
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14},
// {30,30,20,10,14}
//};
int a[10][5];
char m_class[5] = { 'A','B','C','D','E' };
int i = 0, j = 0;
//输入A,B,C,D,E五科成绩
for (i = 0; i < 10; i++)
{
for (j = 0; j < 5; j++)
{
printf("请按顺序输入%s科目的学生成绩\n", &a[i]);
scanf("%d", a[i][j]);
}
}
arr_student(a);
arr_lesson(a);
goodstudent(a);
}
C homework
最新推荐文章于 2020-11-13 18:37:34 发布