#include<stdio.h>
struct stu
{
int number;
int MT;
int EN;
int PH;
int sum;
float ave;
};
typedef struct stu stu;
int main()
{
printf("Input the total number of the students(n<40):");
int n;
scanf("%d", &n);
printf("Input student’s ID and score as: MT EN PH:\n");
int i = 0, SumofCourse[3] = { 0 };
float AverofCourse[3] = { 0.0f };
stu a[40];
for (i = 0; i < n; i++)
{
scanf("%d", &a[i].number);
scanf("%d", &a[i].MT);
scanf("%d", &a[i].EN);
scanf("%d", &a[i].PH);
a[i].sum = a[i].MT + a[i].EN + a[i].PH;
a[i].ave = 0.0f;
a[i].ave = (float)(a[i].sum)/3;
}
printf("Counting Result:\n");
printf("Student’s ID\t MT \t EN \t PH \t SUM \t AVER\n");
for (i = 0; i < n; i++)
{
printf("%12ld\t", a[i].number);
printf("%4d\t", a[i].MT);
printf("%4d\t", a[i].EN);
printf("%4d\t", a[i].PH);
printf("%4d\t%5.1f\n", a[i].sum, a[i].ave);
}
for (i = 0; i < n; i++)
{
SumofCourse[0] += a[i].MT;
SumofCourse[1] += a[i].EN;
SumofCourse[2] += a[i].PH;
}
printf("SumofCourse \t");
for (i = 0; i < 3; i++)
{
printf("%4d\t", SumofCourse[i]);
}
printf("\nAverofCourse\t");
for (i = 0; i < 3; i++)
{
AverofCourse[i] = (float)SumofCourse[i]/n;
printf("%4.1f\t", AverofCourse[i]);
}
return 0;
}
12-29
1万+
12-02
4767
12-27
5484