C语言结构体输出的是分数低的,哪里错了
#include<stdio.h>#define N 3
struct xx
{
char name[20];
char sex;
float score[4];
float peraver;
} stu[N];
void input (struct xx *pstu, int n);
void jisuan (struct xx *pstu, int n, float *pall);
void compare (struct xx *pstu, int n);
void output (struct xx *pstu, int n, float *pall);
int main ()
{
float allaver;
input (stu, N);
jisuan (stu, N, &allaver);
compare (stu, N);
output (stu, N, &allaver);
return 0;
}
计算某班N个学生4门课程的平均成绩,输入姓名,性别,成绩,输出平均成绩高于N个学生总平均成绩的男生的信息
void input (struct xx *pstu, int n)
{
int i, j;
for (i = 0; i < n; i++)
{
printf ("请输入姓名:\n");
scanf ("%s", pstu[i].name);
getchar ();
printf ("请输入性别:\n");
scanf ("%c", &pstu[i].sex);
getchar ();
for (j = 0; j < 4; j++)
{
printf ("请输入成绩:\n");
scanf ("%f", &pstu[i].score[j]);
}
}
}
void jisuan (struct xx *pstu, int n, float *pall)
{
int i, j;
float a = 0, b = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < 4; j++)
{
a += pstu[i].score[j];
}
pstu[i].peraver = a / 4;
b += pstu[i].peraver;
}
*pall = b / 4;
}
void compare (struct xx *pstu, int n)
{
int i, j;
struct xx temp;
for (i = 0; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
if (pstu[i].peraver > pstu[j].peraver)
{
temp = pstu[i];
pstu[i] = pstu[j];
pstu[j] = temp;
}
}
}
}
void output (struct xx *pstu, int n, float *pall)
{
int i, j;
for (i = 0; i < n; i++)
{
if (pstu[i].peraver < *pall && pstu[i].sex == 'm')
{
printf ("%s\t%c\t", pstu[i].name, pstu[i].sex);
for (j = 0; j < 4; j++)
{
printf ("%f\t", pstu[i].score[j]);
}
printf ("\n");
}
}
}