求助:结构体,struct
#include<stdio.h>struct student
{
int no;
char name[30];
char sex;
int score[3];
int sum;
float average;
};
main()
{
struct student stu1;
int i;
stu1.sum=0;
printf("\t\t\t请输入学号:");
scanf("%d",&stu1.no);
printf("\t\t\t请输入名字:");
scanf("%s",&stu1.name);
printf("\t\t\t请输入性别:");
scanf("%s",&stu1.sex);
printf("\t\t\t请输入三课分数:");
for(i=0;i<3;i++)
{
scanf("%d",&stu1.score[i]);
stu1.sum=stu1.score[i]+stu1.sum;
}
stu1.average=stu1.sum/3.0;
printf("no:%d,name:%s,sex:%s,sum:%d,average:%f",stu1.no,stu1.name,stu1.sex,stu1.sum,stu1.average);
}
当输入数组时,内存出错
[ 本帖最后由 linxinqiang 于 2010-11-20 20:23 编辑 ]