C语言编程。一班级三十人。五门课程。编程..1。所有课程最高分。二...
发布网友
发布时间:2024-09-11 11:46
我来回答
共3个回答
热心网友
时间:2024-10-21 23:52
#include<stdio.h>
void main()
{
int a[30][5],i,j,max,min,m,n;
printf("input students'scores:\n");
for(i=0;i<30;i++)
{
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
}
max=a[0][0];
for(i=0;i<30;i++)
{
for(j=0;j<5;j++)
if(a[i][j]>max)
{
max=a[i][j];
}
}
printf("max=%d\n",max);
min=a[0][0];
for(j=0;j<5;j++)
{
for(i=0;i<30;i++)
if(a[i][j]<min)
{
min=a[i][j];
m=i;
n=j;
}
printf("lesson=%d,student=%d\n",n,m);
}
}
热心网友
时间:2024-10-21 23:53
122333
热心网友
时间:2024-10-21 23:54
#include <stdio.h>
#include <string.h>
const int MAX_NUM = 5;
const int MAX_NAME_LEN = 127;
const int MAX_SUBJECT = 3;
const double SUBJECTS = 3.0;
typedef struct _Student
{
char szName[MAX_NAME_LEN + 1];
int nArryScore[MAX_SUBJECT];
int nSum;
double dAverage;
}Student;
void Sort(Student students[], int n)
{
Student stTmp;
int nTmp = 0;
int nPos = 0;
int nIndex = 0;
for (nPos = 0; nPos < n - 1; nPos++)
{
nTmp = nPos;
memset(&stTmp, 0, sizeof(Student));
for (nIndex = nPos + 1; nIndex < n; nIndex++)
{
if (students[nIndex].nSum > students[nTmp].nSum)
{
nTmp = nIndex;
}
}
memcpy(&stTmp, &students[nTmp], sizeof(Student));
memcpy(&students[nTmp], &students[nPos], sizeof(Student));
memcpy(&students[nPos], &stTmp, sizeof(Student));
}
}
int main (void)
{
printf("请输入五个同学三门课的成绩:\n");
Student students[MAX_NUM];
memset(students, 0, sizeof(students));
Student* pStudent = NULL;
int nCnt = 0;
int nPos = 0;
while (MAX_NUM > nCnt)
{
printf("第%d个同学的记录:", nCnt + 1);
pStudent = &students[nCnt];
scanf("%s %d %d %d", pStudent->szName,
&pStudent->nArryScore[0],
&pStudent->nArryScore[1],
&pStudent->nArryScore[2]);
for (nPos = 0; nPos < MAX_SUBJECT; nPos++)
{
pStudent->nSum += pStudent->nArryScore[nPos];
}
pStudent->dAverage = pStudent->nSum / SUBJECTS;
nCnt++;
getchar();
}
Sort(students, MAX_NUM);
printf("------------------------------------------------\n");
printf("输出排序后五个同学的三门成绩:\n");
printf("------------------------------------------------\n");
printf("排序 姓名 课1 课2 课3 总分 平均分\n");
for (nPos = 0; nPos < MAX_NUM; nPos++)
{
pStudent = &students[nPos];
printf("第%d名: %s %d %d %d %d %.2f\n", nPos + 1,
pStudent->szName,
pStudent->nArryScore[0],
pStudent->nArryScore[1],
pStudent->nArryScore[2],
pStudent->nSum,
pStudent->dAverage);
}
return 0;
}