#include<stdio.h>
struct Student
{
int number;
char name[20];
int a1;
int a2;
int a3;
int sum;
};
int total(struct Student stu)
{
stu.sum = stu.a1 + stu.a2 + stu.a3;
return stu.sum;
}
void paixu(struct Student stu[])
{
int i,j;
struct Student temp;
for (i = 1; i < 3; i++)
{
for (j = i + 1; j <= 3; j++)
{
if (stu[i].sum > stu[j].sum)
{
temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
}
}
int main()
{
struct Student stu[3];
int i,j;
for (i = 1; i <= 3; i++)
{
scanf("%d%s%d%d%d", &stu[i].number, stu[i].name, &stu[i].a1, &stu[i].a2, &stu[i].a3);
stu[i].sum=total(stu[i]);
}
paixu(stu);
for (i = 1; i <= 3; i++)
{
printf("%d %s %d %d %d\n", stu[i].number, stu[i].name, stu[i].a1, stu[i].a2, stu[i].a3);
}
return 0;
}
MicrosoftVisualC++RuntimeLibrary DebugError' Program.D:\code2\Project12_16\x64\Debug\Project12一16.“e Module:D:\code2\Project12_16\x64\Debug\Pr0ject12_16.exe Run-TimeCheckFailure#2-Stackaroundthevariable'Stu'was corrupted. (PressRetrytodebugtheapplication) 就老给我报错这个,是哪里越界了吗???刚学完结构体还不太会