C语言用结构写的出现段错误怎么解决?
http://pat.zju.edu.cn/contests/pat-b-practise/1004#include<stdio.h>#defineN50structst...
http://pat.zju.edu.cn/contests/pat-b-practise/1004
#include<stdio.h>
#define N 50
struct student{
char name[11], studentNum[11];
double score;
};
int main(){
struct student studentArray[N];
struct student maxScore;
struct student minScore;
int n, i;
scanf("%d", &n);
for (i = 0; i < n; ++i){
scanf("%s%s%lf", studentArray[i].name, studentArray[i].studentNum, &studentArray[i].score);
}
maxScore = studentArray[0];
minScore = studentArray[0];
for (i = 1; i < n; ++i){
if (studentArray[i].score>maxScore.score){
maxScore = studentArray[i];
}
if (studentArray[i].score<minScore.score){
minScore = studentArray[i];
}
}
printf("%s %s\n", maxScore.name, maxScore.studentNum);
printf("%s %s\n", minScore.name, minScore.studentNum);
return 0;
}
第三个测试数据出现段错误。怎么解决? 展开
#include<stdio.h>
#define N 50
struct student{
char name[11], studentNum[11];
double score;
};
int main(){
struct student studentArray[N];
struct student maxScore;
struct student minScore;
int n, i;
scanf("%d", &n);
for (i = 0; i < n; ++i){
scanf("%s%s%lf", studentArray[i].name, studentArray[i].studentNum, &studentArray[i].score);
}
maxScore = studentArray[0];
minScore = studentArray[0];
for (i = 1; i < n; ++i){
if (studentArray[i].score>maxScore.score){
maxScore = studentArray[i];
}
if (studentArray[i].score<minScore.score){
minScore = studentArray[i];
}
}
printf("%s %s\n", maxScore.name, maxScore.studentNum);
printf("%s %s\n", minScore.name, minScore.studentNum);
return 0;
}
第三个测试数据出现段错误。怎么解决? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询