LectC13chap09结构及其存储.pptVIP

  • 5
  • 0
  • 约8.83千字
  • 约 38页
  • 2018-01-02 发布于湖北
  • 举报
LectC13chap09结构及其存储.ppt

例9-4 结构数组排序 输入并保存10个学生的信息,计算并输出平均分,再按照从高分到低分的顺序输出他们的信息。 #include stdio.h struct student{ int num; char name[20]; int score; }; struct student stud[10]; /* 定义结构数组 */ 例9-4 源程序 int main(void) { int i, j, index, sum = 0; struct student temp; /* 输入10个学生的记录,并累加成绩 */ for(i = 0; i 10; i++){ printf(No %d: , i+1); scanf(%d%s%d, stud[i].num, stud[i].name, stud[i].score); sum = sum + stud[i].score; } /* 按照分数从低到高排序,使用选择排序法 */ for( i = 0; i 9; ++i ){ index =i; for (j = i+1; j 10; j++ ) if (stud[j].sco

文档评论(0)

1亿VIP精品文档

相关文档