一个c结构程序问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:28:16
#include <stdio.h>
#define N 5

struct student
{
int sno;
char name[10];
float score_c;
float score_java;
}stu[N]={
{1,"lineage",88,87},
{2,"billy",79,99},
{3,"jimmy",56,89},
{4,"bob",66,98},
{5,"pears",80,55}};

void ave(float m,float n);

void main()
{
int i;
float ave[5];
for(i=0;i<N;i++)
{
ave[i]=ave(struct student stu[i].score_c,struct student stu[i].score_java);
}

}

void ave(float m,float n)
{
float sum,ave;
sum=m+n;
ave=sum/2;
printf("%.2f",ave);
}

请高手看看它题目要求定义一个结构,用来保存学员的信息,上面我已经定义好了。要求用函数来计算平均成绩。我老是提示有错误,请帮忙!~~急!

#include <stdio.h>
struct student
{
int sno;
char name[10];
float score_c;
float score_java;
}
void av(float,float,char);
main()
{
int i;
float a,b;
char c;
struct student ave[5]={
{1,"lineage",88,87},
{2,"billy",79,99},
{3,"jimmy",56,89},
{4,"bob",66,98},
{5,"pears",80,55}};
for(i=0;i<5;i++)
{
a=ave[i].score_java;
b=ave[i].score_c;
c=ave[i].name;
av(a,b,c);
}
}

void av(float m,float n,char z)
{
float sum,ave;
sum=m+n;
ave=sum/2;
printf("%s的总分是:%.2f\t平均分是:%.2f\n",z,sum,ave);
}

正确答案~
1.结构体相当于一个数据类型,和int的用法一样,如上:struct student你可以看做是一个数据类型 ave[5]就是数组名。和定义int ave[5]是一样的道理。然后直接给ave[5]赋值
2.函数要在主函数里调用,另外要声明原函数。
3.调用函数时传的参是实参,需要有声明。
4.尽量不要过多的重名,你的结构体变量(数组)和