...每个学生考试三门功课(数学、英语、计算机基础)的成绩
发布网友
发布时间:2023-12-28 08:05
我来回答
共3个回答
热心网友
时间:2024-08-06 10:45
#include<stdio.h>
#define N 10
typedef struct student
{ char num[14];
int score[3];
int sum;
int rank;
float aver; } /* sum是总分,aver是平均分*/
Student;Student stu[50]; /*定义结构体数组*/
void sum_and_aver(Student stu1[ ],int count) /*计算总分和平均分函数*/
{ int i, j;
for(i=0; i<count; i++)
{stu1[i].sum=0; stu1[i].aver=0;
for(j=0; j<3; j++)
stu1[i].sum += stu1[i].score[j];
stu1[i].aver= (float)stu1[i].sum/3;
}
}
void sort(Student stu2[ ], int count) /*定义排序函数*/
{
int i, j;
Student t;
for(i=0; i<=count-1; i++)
for(j=1; j<=count-i; j++)
if(stu2[j-1].sum<stu2[j].sum)
{ t = stu2[j-1];
stu2[j-1] = stu2[j];
stu2[j] = t;
}
}
void main() /*定义主函数*/
{ void sum_and_aver(Student stu1[ ], int count);
void sort(Student stu2[ ], int count);
int i;
for(i=0;i<N;i++)
{ printf("please input students' id and scores inturn:id math english computer\n");
scanf("%s%d%d%d",stu[i].num,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
} /*输入学生信息*/
sum_and_aver(stu,N); /*引用计算总分和平均分的函数*/
sort(stu,N); /*引用排序函数*/
printf("This is the list:\n");
printf("rank students'id math english computer sum average\n");
for(i=0;i<N;i++)
printf("%4d %s %4d %7d %8d %3d %.1f\n",i+1,stu[i].num,stu[i].score[0],
stu[i].score[1],stu[i].score[2],stu[i].sum,stu[i].aver);
}
6.实验结果:
please input students' num and scores inturn: math english computer
200732541101 96 98 96
please input students' num and scores inturn: math english computer
200732541102 98 78 87
please input students' num and scores inturn: math english computer
200732541103 54 52 68
please input students' num and scores inturn: math english computer
200732541104 75 94 85
please input students' num and scores inturn: math english computer
200732541105 54 84 86
please input students' num and scores inturn: math english computer
200732541106 74 75 76
please input students' num and scores inturn: math english computer
200732541107 71 37 72
please input students' num and scores inturn: math english computer
200732541108 72 74 79
please input students' num and scores inturn: math english computer
200732541109 84 81 82
please input students' num and scores inturn: math english computer
200732541110 54 67 68
rank num math english computer sum average
1 200732541101 96 98 96 290 96
2 200732541102 98 78 87 263 87
3 200732541104 75 94 85 254 84
4 200732541109 84 81 82 247 82
5 200732541106 74 75 76 225 75
6 200732541105 54 84 86 224 74
7 200732541108 72 70 79 221 73
8 200732541110 54 67 68 189 63
9 200732541107 71 37 72 180 60
10 200732541103 54 52 68 180 58
热心网友
时间:2024-08-06 10:42
刚学完链表,现学现卖~(自己写的,需要注释再给你填上~)
#include "stdio.h"
#define N 10
struct student{
int number;
int sx;
int yy;
int jsj;
struct *next;
};
void main()
{
struct student *p,*q,*head;
int i=0,j,temp;
int a[N],b[N];
head=NULL;
q=NULL;
while(i<N){
p=(struct student *)malloc(sizeof(struct student));
printf("请输入第%d名同学的学号",i+1);
scanf("%d",&p->number);
printf("请输入第%d名同学的数学成绩",i+1);
scanf("%d",&p->sx);
printf("请输入第%d名同学的英语成绩",i+1);
scanf("%d",&p->yy);
printf("请输入第%d名同学的计算机成绩",i+1);
scanf("%d",&p->jsj);
a[i]=((p->jsj)+(p->sx)+(p->yy));
b[i]=a[i]/3;
if(head==NULL){
head=p;
}
q=p->next;
p=p->next;
i++;
}
for(i=0;i<N;i++)
for(j=0;j<5;j++){
if(a[j]<a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+i]=temp;
}
}
for(i=0;i<N;i++){
printf("第%d名同学总分为%d\n",i+1,a[i]);
}
}
热心网友
时间:2024-08-06 10:44
这么麻烦的题目。。。。
void sort(float *all, int n, int *order){
int i,j,k;
float f;
for (i=0;i<n;i++) order[i] = i;
for (i=0;i<n-1;i++)
for (j=i+1;j<n;j++){
if (all[j] > all[i]) {
f=all[j]; all[j]=all[i]; all[i]=f;
k = order[j];order[j]=order[i];order[i]=k;
};
};
}
void main ()
{
int id[10];
float m1[10],m2[10],m3[10],all[10];
int order[10];
int i,k,n=10;
printf("please input id math Eng comp scores\n");
for (i=0;i<n;i++) {
scanf("%d %f %f %f",&id[i],&m1[i],&m2[i],&m3[i]);
all[i] = m1[i]+ m2[i] + m3[i];
};
sort( &all[0], n, &order[0]);
for (i=0;i<n;i++){
k = order[i];
printf("%d %d %f %f %f %f %f\n",i+1,id[k],m1[k],m2[k],m3[k],all[i],all[i]/3.0);
};
}