这个程序你什么时候要,我可以帮你写,但要点时间
既然写了我也放着吧,供他人参考一下
#include
#include
#define max_number 3//十个学生
struct student
{
int number_student;
char name_student[20];
float math;
float english;
float chinese;
};
struct student s[max_number];
void input(struct student s[max_number])
{
int i;
printf("Please input the information of students:\n");
for (i=0;i{
printf("第%d个学生学号:",i+1);
scanf("%d",&s[i].number_student);
getchar();
printf("第%d个学生姓名:",i+1);
gets(s[i].name_student);
printf("第%d个学生数学成绩:",i+1);
scanf("%f",&s[i].math);
printf("第%d个学生英语成绩:",i+1);
scanf("%f",&s[i].english);
printf("第%d个学生语文成绩:",i+1);
scanf("%f",&s[i].chinese);
}
printf("\n");
}
void average1(float sum_student[max_number])
{
int i;
for (i=0;i{
printf("第%d个学生的3门课的平均成绩: ",i+1);
sum_student[i] = s[i].chinese+s[i].english+s[i].math;
printf("%f\n",sum_student[i]);
}
}
void average2(float x[3])
{
int i;
for (i=0;i<3;i++)
{
x[i]=0.0;
}
for(i=0;i{
x[0] += s[i].math;
x[1] += s[i].chinese;
x[2] += s[i].english;
}
printf("the average of math is: %f\n",x[0]/max_number);
printf("the average of chinese is: %f\n",x[1]/max_number);
printf("the average of english is: %f\n",x[2]/max_number);
printf("\n");
}
void sort(struct student s[max_number])//按总成绩排序
{
struct student temp;
int i,j;
for (i=0;i{
for(j=i;j{
if ((s[i].chinese+s[i].english+s[i].math)<(s[j].chinese+s[j].english+s[j].math))
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}
void output(struct student s[max_number])
{
int i;
sort(s);
printf("总成绩表为\n");
for (i=0;i{
printf("第%学生学号:",i+1);
printf("%d\n",s[i].number_student);
printf("第%d学生姓名:",i+1);
puts(s[i].name_student);
printf("第%d学生数学成绩:",i+1);
printf("%f\n",s[i].math);
printf("第%d学生英语成绩:",i+1);
printf("%f\n",s[i].english);
printf("第%d学生语文成绩:",i+1);
printf("%f\n",s[i].chinese);
printf("\n");
}
}
void main()
{
float average[max_number];
float avg_student[3];
input(s);
average1(average);
average2(avg_student);
output(s);
}
呃,楼上的已经说要帮助了哈,不过我正好都写出来了,还是放出代码吧,仅供参考啦。
#include
typedef struct {
int number;
char name[20];
float score[3];
float avg;
}STU;
void input(STU stu[])
{
for(int i=0;i<10;i++)
{
printf("输入第%d个学生的信息:\n",i+1);
scanf("%d %s %f %f %f",&stu[i].number,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
}
void average1(STU stu[])
{
printf("\n");
for(int i=0;i<10;i++)
{
stu[i].avg = (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
printf("学生 %5s 的三门课平均成绩为:%5.2f\n",stu[i].name,stu[i].avg);
}
}
void average2(STU stu[])
{
float sum_score[3] ;
sum_score[0] = stu[0].score[0];
sum_score[1] = stu[0].score[1];
sum_score[2] = stu[0].score[2];
for(int i=1;i<10;i++)
{
sum_score[0] += stu[i].score[0];
sum_score[1] += stu[i].score[1];
sum_score[2] += stu[i].score[2];
}
printf("\n");
printf("所有学生第一门课平均成绩为:%5.2f\n",sum_score[0]/10);
printf("所有学生第二门课平均成绩为:%5.2f\n",sum_score[1]/10);
printf("所有学生第三门课平均成绩为:%5.2f\n",sum_score[2]/10);
}
void sort(STU stu[])
{
float k;
for(int j=0;j<10;j++) //这个地方用起泡排序法好,但我忘了,这个方法计算次数多\(^o^)/~
for(int i =0;i<10;i++)
if(stu[i].avg { k= stu[i].avg; stu[i].avg =stu[i+1].avg; stu[i+1].avg =k; } printf("\n平均成绩从高到低的学生排序为:\n"); for(int n = 0;n<10;n++) printf("%-5s %5.2f %5.2f %5.2f 平均分为 %5.2f\n",stu[n].name,stu[n].score[0],stu[n].score[1],stu[n].score[2],stu[n].avg); } void output(STU stu[]) { printf("\n成绩表为:\n"); for(int i=1;i<10;i++) { printf("学号\t姓名\t第一科\t第二科\t第三科\t平均成绩\n"); printf("%3d\t%5s\t%5.2f\t%5.2f\t%5.2f\t%5.2f\n",stu[i].number,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].avg); } } void main() { STU stu[10]; input(stu); average1(stu); average2(stu); sort(stu); output(stu); } 运行结果部分截图: