C语言高手请进!帮小弟编编这个程序: 输入5个学生4门课程的成绩,求各学生成绩的总分和平均数.

应该是用二维数组吧。我都调试N次了,还老是出错,只好求助高手了!

应该是这样,你试试吧

输入5个学生4门功课的成绩,然后求出:
每个学生的总分;
每门课程的平均分;
输出总分最高的学生的姓名与成绩。
提示:首先定义一个char 类型数组name[5][10]存放5个学生的姓名,再定义一个int 类型数组student_score[5][4]来存放5个学生的4门功课成绩,再定义一个类型数组each_total[5]用来存放每个学生的总成绩。

#include <stdio.h>
#define STU 5
#define CLA 4
//print score
void print_score(int count, float *score)
{
int i;
for(i=0;i<count;i++)
printf("%.2lf\n",*(score+i));
}
//each student total score
void stu_total(float student_score[][4], float each_total[])
{
int i,j;
float *s=each_total; //此处是指向数组元素的指针
for(i=0;i<STU;i++)
for(j=0;j<CLA;j++)
{
each_total[i]+=student_score[i][j];
}
printf("each total scores is:\n");
print_score(STU,s);
//此处也可以写成
print_score(STU,each_score);

}
//average score of each class
void class_avg(float student_score[][4])
{
int i,j;
float tmp[4];
float *s=tmp;
for(i=0;i<CLA;i++)
{
for(j=0;j<STU;j++)
tmp[i]+=student_score[i][j];
tmp[i]=tmp[i]/STU;
}
printf("The average of each class is \n");
print_score(CLA,s);
}

//locate name
void print_name(int location,char name[][10])
{
printf("%s\n",*(name+location));
}

//highest score and student's name
void highest_score(float a[],char name[][10])
{
int i,k;
float highest=0;
for(i=0;i<STU;i++)
{
if(*(a+i)>highest)
{
highest=*(a+i);
k=i;
}
}
printf("The student name of highest total scores is:");
print_name(k,name);
printf("highest total scores is:%.2lf\n",highest);

}
void main()
{
int i,j;
float student_score[5][4];
float each_total[5];
char name[5][10];
//enter name
printf("please enter name by order:\n");
for(i=0;i<5;i++)
{
scanf("%s",name[i]);
}
//enter scores
for(i=0;i<5;i++)
{
printf("please enter num%3d student's each class score:\n",i+1);
for(j=0;j<4;j++)
scanf("%f",&student_score[i][j]);
}
//each student total scores
stu_total(student_score, each_total);
//each class average scores
class_avg(student_score);
//highest score and student's name
highest_score(each_total, name);

}
//注意二维数组做函数参数,必须指明最后一维的维数,在调用参数为数组的函数时,不用加维数,为传址调用,轻易不要用指向数组的指针,注意:指向数组的指针和指向数组元素的指针是不一样的
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-06-06
#include <stdio.h>
void main()
{
int stu[5][4],i,j,t[5];
float sum=0,a[5];
for(i=0;i<5;i++)
for(j=0;j<4;j++)
scanf("%d",&stu[i][j]);
for(i=0;i<5;i++)
{t[i]=0;
for(j=0,j<4;j++)
{sum=sum+stu[i][j];
t[i]=t[i]+stu[i][j];每个学生的总成绩
}
printf("%-5d",t[i]);
a[i]=t[i]/4.0;每个学生的平均成绩
printf("%-5.2d",a[i]);}
}这样写还行啊吧本回答被提问者采纳
相似回答