qq_35156130 2017-05-18 14:07 采纳率: 33.3%
浏览 1127

求教大佬,这段代码为什么在codeblocks下宏定义为1时正常运行,不为1时运行停止

#include
#include
#include
#include
#define NO 'F'
#define YES 'P'
#define PASSLINE 320
#define PASSLINE1 75
#define PASSLINE2 45
#define N 1
int npass=0;
struct Stu_Score
{
int number;
char name[20];
double Eng_score;
double mat_score;
double maj_score;
double pol_score;
double sum_score;
char state;
}stu[N];
void Cal_Mark(int i)
{
stu[i].sum_score=stu[i].mat_score+stu[i].Eng_score+
stu[i].pol_score+stu[i].maj_score;
if(stu[i].sum_score>=PASSLINE && stu[i].mat_score>=PASSLINE1 &&
stu[i].maj_score>=PASSLINE1 && stu[i].Eng_score>=PASSLINE2 &&
stu[i].pol_score>=PASSLINE2)
{
stu[i].state=YES;
stu[i].state=YES;
npass++;
}
else
stu[i].state=NO;
}
void exchange(struct Stu_Score *p,struct Stu_Score *q)
{
struct Stu_Score *temp;
temp->number=p->number;
strcpy(temp->name,p->name);
temp->Eng_score=p->Eng_score;
temp->mat_score=p->mat_score;
temp->maj_score=p->maj_score;
temp->pol_score=p->pol_score;
temp->sum_score=p->sum_score;
temp->state=p->state;
mp->state=p->state;
p->number=q->number;
strcpy(p->name,q->name);
p->Eng_score=q->Eng_score;
p->mat_score=q->mat_score;
p->maj_score=q->maj_score;
p->pol_score=q->pol_score;
p->sum_score=q->sum_score;
p->state=q->state;
q->number=temp->number;
strcpy(q->name,temp->name);
q->Eng_score=temp->Eng_score;
q->mat_score=temp->mat_score;
q->maj_score=temp->maj_score;
q->pol_score=temp->pol_score;
q->sum_score=temp->sum_score;
q->state=temp->state;
printf("0000000");
printf("0000000");
}
void SelectionSort(struct Stu_Score stu[])
{
int i,j,k;
for(i=0;i {
k=i;
for(j=i+1;j if(stu[j].sum_score>stu[i].sum_score)
k=j;
if(k!=i)
exchange(&stu[i],&stu[k]);
}
}
int main()
{
int i;
int i;
for(i=0;i<N;i++)
{
system("cls");
printf("请输入NO.%d学生的信息:\n",i+1);
printf("学号:");
scanf("%d",&stu[i].number);
printf("姓名:");
scanf("%s",stu[i].name);
printf("数学成绩:");
scanf("%lf",&stu[i].mat_score);
printf("英语成绩:");
scanf("%lf",&stu[i].Eng_score);
printf("政治成绩:");
scanf("%lf",&stu[i].pol_score);
printf("专业课成绩:");
scanf("%lf",&stu[i].maj_score);
scanf("%lf",&stu[i].maj_score);
}
for(i=0;i<N;i++)
Cal_Mark(i);
SelectionSort(stu);
system("cls");
if(npass)
{
printf("满足要求的学生的复试名单为:\n");
printf("学号\t姓名\t外语\t数学\t政治\t专业课\t总成绩\n");
for(i=0;i<N;i++)
if(stu[i].state==YES)
{
if(stu[i].number/10==0)
printf("00%d\t",stu[i].number);
else if(stu[i].number/100==0)
else if(stu[i].number/100==0)
printf("0%d\t",stu[i].number);
else
printf("%d\t",stu[i].number);
printf("%s\t%g\t%g\t%g\t%g\t%g\n",stu[i].name,
stu[i].Eng_score,stu[i].mat_score,
stu[i].pol_score,stu[i].maj_score,
stu[i].sum_score);
}
}
else
printf("没有满足要求的学生!");
return 0;
}

  • 写回答

2条回答

  • qq_35156130 2017-05-18 14:07
    关注

    宏定义的N为1时正常运行,不为1时出错显示已停止工作

    评论

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复