|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#define N 3
struct student {
char name[20];
float score[4];
};
void fenshu(struct student stu[],int n);
int main() {
struct student stu[N];
fenshu(stu,N);
return 0;
}
void fenshu(struct student stu[],int n) {
int i;
for(i = 0;i < n;i++) {
printf("输入第%d位学生姓名:",i + 1);
scanf("%s",&stu[i].name);
printf("请输入数学,语文,英语成绩(逗号隔开):");
scanf("%f,%f,%f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].score[3] = (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
}
for(i = 0;i < n;i++) {
printf("%s同学的平均分是%6.2f\n",stu[i].name,stu[i].score[3]);
}
}
函数里定义的结构体是局部变量,在这个函数外是不能使用的。
你要在函数外定义成全局变量。
|
|