/*
输入一个班M个学生N门课程的成绩,计算出每门课程全班的平均分,最高分,最低分,及格率和优秀率.
(学生人数M,课程数N及所有分数均由键盘输入.)
问题补充:没有用到类,用循环语句的.
*/
#include
void main(void)
{
float s[100][20]; /*最多可容纳100学生的20门成绩*/
float a[20][5]; /*a[][0]20门课的平均分 a[][1]最高分 a[][2]最低分 a[][3]及格率 a[][4]优秀率*/
int m,n,i,j;
printf("enter student number M:");
scanf("%d",&m);
printf("enter student curse number n:");
scanf("%d",&n);
for(i=0; i
printf("\nenter student %d ",i+1);
for(j=0; j
printf("\ncurse %d:",j+1);
scanf("%f",&s[i][j]);
}
}
for(j=0; j
a[j][0]=0; /*平均分*/
a[j][1]=s[0][j]; /*最高分*/
a[j][2]=s[0][j]; /*最低分*/
a[j][3]=0; /*及格率*/
a[j][4]=0; /*优秀率*/
for(i=0; i
a[j][0]+=s[i][j];
if(s[i][j]>a[j][1]) /*最高分*/
a[j][1]=s[i][j];
if(s[i][j] a[j][2]=s[i][j];
if(s[i][j]>=60) /*及格率*/
a[j][3]++;
if(s[i][j]>=90) /*优秀率*/
a[j][4]++;
}
a[j][0]/=m; /*平均分*/
a[j][3]=a[j][3]/m*100; /*及格率*/
a[j][4]=a[j][4]/m*100; /*优秀率*/
}
for(i=0; i
printf("\n course %d average: %.f top score=%.f low score=%.f \n up_rate=%.f good_rate=%.f",i+1,a[i][0],a[i][1],a[i][2],a[i][3],a[i][4]);
}
}
#include
#include
#define StuMax 60 /* Max Students Num */
#define ClsMax 10 /* Max Classes Num */
#define ScorePass 60
#define ScoreWell 80
typedef struct
{
float average; /* Average of this Class */
float maxscore; /* Max Score */
float minscore; /* Min Score */
float perpass; /* Percentage of Passed Students */
float perwell; /* Percentage of Done well */
} Class;
typedef struct
{
float scores[ClsMax];
} Student;
/* Global Variables */
Student students[StuMax];
Class classes[ClsMax];
int stunum, clsnum; /* count of students, count of classes */
void fillrecords()
{
int i, j;
for(i = 0; i < stunum; i++)
{
printf("\n Inputing Information of Student %0d", i+1);
for(j = 0; j < clsnum; j++)
{
printf("\n Class %0d", j);
scanf("%f", students[i].scores[j]);
}
}
printf("\n\n");
}
void operaterecords()
{
int i, j;
for(i = 0; i < clsnum; i++)
{
classes[i].average = 0;
classes[i].maxscore = 0; classes[i].minscore = 0;
classes[i].perpass = 0; classes[i].perwell = 0;
for(j = 0; j < stunum; j++)
{
classes[i].average += students[j].scores[i];
if(students[j].scores[i] > classes[i].maxscore)
classes[i].maxscore = students[j].scores[i];
if(students[j].scores[i] < classes[i].minscore)
classes[i].minscore = students[j].scores[i];
if(students[j].scores[i] >= ScorePass)
classes[i].perpass++; /* Passed num ++ */
if(students[j].scores[i] >= ScoreWell)
classes[i].perwell++; /* Done well num ++ */
}
/* output information of this class */
printf("\n Statistics of Class %0d", i+1);
printf("\n\t Average : %f", classes[i].average / stunum);
printf("\n\t MaxScore : %f", classes[i].maxscore);
printf("\n\t MinScore : %f", classes[i].minscore);
printf("\n\t PerPass : %f%", classes[i].perpass / (stunum * 100));
printf("\n\t PerWell : %f%", classes[i].perwell / (stunum * 100));
}
}
int main()
{
printf("\nNumber of Students: ");
scanf("%d", stunum); /* Validating required, do it yourself */
printf("\nNumber of Classes : ");
scanf("%d", clsnum); /* Validating required, do it yourself */
fillrecords(); operaterecords(); getch();
return 0;
}
没有对输入的合法性进行判断,你自己搞定吧
# include stdlib.h"
struct stu
{float max;
float min;
float aver;
float pass;
float excel;};
main()
{int m,n;
float *a;
struct stu *b;
int i,j;
foat max,min,aver=0,pass,excel;
scanf("%d%d",&m,&n);
a=(float *)malloc(sizeof(float)*m*n);
b=(struct stu *)malloc(sizeof(struct stu)*n);
for(i=0;i
for(i=0;i
b[i].aver=b[i].pass=b[i].excel=0;
for(j=0;j
if(a[j][i]>=60) b[i].pass++;
if(a[j][i]>=85) b[i].excel++;
b[i].aver=b[i].aver+a[j][i];}
aver=aver/m;
b[i].pass=b[i].pass/m;
b[i].excel=b[i].excel/m;}
for(i=0;i
{printf("%5.2f%5.2f%5.2f%5.2f%5.2f\n",
b[i].max,b[i].min,b[i].aver,b[i].pass,
b[i].excel);}
getch();}
我想要用函数重载吧,我学的C++,不知道你们C里有没有这个,太简单了,要自己动手!学编程,最重要的就是会编写程序
哎呀,谁用汇编写一个吧,我也要.别忘了加注释啊.这个很重要.
要汇编写的吗?
我用GCC自己编译出的汇编代码,不也是汇编的吗?