#include"stdio.h"
#include"stdlib.h"
#define N 10
struct stduent
{
char no[12];
char name[10];
float score[3];
float average;
}stu[N];
void input(int n)
{
int i, j;
for (i = 0; i < n; i++)
{
printf("学号:");
gets(stu[i].no);
printf("姓名:");
gets(stu[i].name);
printf("成绩:");
for (j = 0; j < 3; j++)
scanf("%f", &stu[i].score[j]);
fflush(stdin);
}
}
void average(int n)
{
int i, j;
for (i = 0; i < n; i++)
{
stu[i].average = 0;
for (j = 0; j < 3; j++)
stu[i].average += stu[i].score[j];
stu[i].average /= 3;
}
}
int max(int n)
{
float m;
int i, j;
m = stu[0].average;
i = 0;
for(j=1;j
{
m = stu[i].average;
i = j;
}return i;
}
int main()
{
int i;
input(N);
average(N);
printf("|sfiusgfyuwgfqwiuygiukwygef\n");
for(i=0;i
i = max(N);
printf("%s|%s|%f|%f|%f|%f\n", stu[i].name, stu[i].no, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].average);
return 0;
}
你定义了全局变量,就不需要再在函数里定义了