求助(简单编程问题)

来源:百度知道 编辑:UC知道 时间:2024/06/18 23:51:45
1. 一个班级有6个学生,共学习5门课。要求编写程序完成下面的三个功能。
(1) 求出第2门功课的平均分;
(2) 找出有两门以上功课不及格的学生,输出该学生的学号和全部课程成绩及平均分。
(3) 找出平均成绩在80分以上或者全部课程成绩在75分以上的学生。

////////////////////////////////////////
#include <stdio.h>
struct student{
float score[5];
}stu[6];
void find1(struct student a[]);
void find2(struct student a[]);
float ave(struct student a);
int u75(struct student a);
int main(int argc, char* argc[])
{
int i,j;
float ave=0;
for (i = 0; i<6; i++) {
for (j=0; j<5; j++) {
scanf("%f",&stu[i].score[j]);
}
}
for (i = 0; i<6; i++) {
ave+=stu[i].score[1]/6;
}
printf("AVERAGE=%g",ave);
printf("SCORE <60:\n");
find1(stu);
printf("-------------------\n");
printf("AVERAGE>80 || SCORE>75 :\n");
find2(stu);
printf("-------------------\n"

终于完成了,修改了很多地方,修改的地方我用//表示,你自己对照看看
错误最明显的地方在于求平均值,你用错了方法,另外main()函数没有外面传递过来的参数,就用void
还有一点,数组大小最好用
#define SIZE 6
这样表示,不然调试程序每次都要输入6个学生的成绩,很累的
以下是源程序,当然还可以改的更好:
#include <stdio.h>
struct student{
float score[5];
}stu[6];
void find1(struct student a[]);
void find2(struct student a[]);
float ave(struct student a);
int u75(struct student a);
int main(int argc, char *argv[])
{
int i,j;
float ave=0;
puts("Enter scores: ");
for (i = 0; i<6; i++) {
printf("Student #%d: ",i+1);//
for (j=0; j<5; j++) {
scanf("%f",&stu[i].score[j]);

}
}

for (i = 0; i<6; i++) {
ave+=stu[i].score[1]/6;
}
printf("AVERAGE=%.2f\n",ave); //
printf("SCORE <60:\n");
find1(stu);
printf("-------------------\n");
printf("AVERAGE>80 ||