定义结构记录学生分数,并由高到低排列出来
2014-11-17 23:10
274 查看
Define a struct type that contains a student’s number, name and score of three courses. Write a program, to enter 5 students’ information(name, number & scores of the 3 courses), and calculate the total score of all three courses, then output the students'
number & name sorted by the total score from high to low.
注意指针不能用%s读取会导致错误
char name【10】正确
但是char *name不正确用scanf读取时候
number & name sorted by the total score from high to low.
注意指针不能用%s读取会导致错误
char name【10】正确
但是char *name不正确用scanf读取时候
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 5 int main(void) { struct studentRecord { int number; char name[10]; float score[4]; float sum; }student ,studentTemp; int i; for(i=0;i<N;++i) { printf("ÊäÈëѧºÅ\tÐÕÃû\t¿ÆÄ¿1³É¼¨\t¿ÆÄ¿2³É¼¨\t¿ÆÄ¿3³É¼¨\n"); scanf("%d %s %f %f %f",&student[i].number,student[i].name,&student[i].score[0],&student[i].score[1],&student[i].score[2]); //printf("1\n"); student[i].sum=student[i].score[0]+student[i].score[1]+student[i].score[2]; } int num ; int j; printf("ѧºÅ\tÐÕÃû\t¿ÆÄ¿1³É¼¨\t¿ÆÄ¿2³É¼¨\t¿ÆÄ¿3³É¼¨\t×Ü·Ö\n"); for(i=0;i<N;i++){ num[i]=i; for(j=i+1;j<N;j++){ if(student[i].sum<student[j].sum){ studentTemp.sum=student[i].sum; studentTemp.number=student[i].number; strcpy(studentTemp.name,student[i].name); studentTemp.score[0]=student[i].score[0]; studentTemp.score[1]=student[i].score[1]; studentTemp.score[2]=student[i].score[2]; student[i].sum=student[j].sum; student[i].number=student[j].number; strcpy(student[i].name,student[j].name); student[i].score[0]=student[j].score[0]; student[i].score[1]=student[j].score[1]; student[i].score[2]=student[j].score[2]; student[j].sum=studentTemp.sum; student[j].number=studentTemp.number; strcpy(student[j].name,studentTemp.name); student[j].score[0]=studentTemp.score[0]; student[j].score[1]=studentTemp.score[1]; student[j].score[2]=studentTemp.score[2]; } } //printf("1\n"); printf("%5d\t%s\t%4.1f\t%12.1f\t%13.1f\t%11.1f\n",student[i].number,student[i].name,student[i].score[0],student[i].score[1],student[i].score[2],student[i].sum); } return 0; }
相关文章推荐
- 2.4 设计评选优秀教师和学生的程序,其类结构如图 12.5 所示。当输入一系列教师 或学生的记录后,将优秀学生及教师的姓名列出来。 图 12.5 类结构 类 base char name[8]; 含
- 用LS,定义一个10位数的数组,并用冒泡法排序,从大到小排列出来
- 学生运动会分数记录系统
- 3、写一个程序,定义一个学生结构体,至少要含4个数据项,其中有一项用来保存学生成绩。用此结构体存储班级上的所有学生信息
- 关于学生按分数排列名次的问题
- C#使用结构体,输入5个人的学号,姓名,分数,按照成绩高低排列打印出来
- 给出n个学生的考试成绩表,每条记录由学号、姓名和分数和名次组成,设计算法完成下列操作: (1)设计一个显示对学生信息操作的菜单函数如下所示: *************************
- 项目名称:已知学生的记录由学号和学习成绩构成,4名学生的数据已存入结构体数a中,请编写程序,找出成绩最低的的学生记录并输出。
- 题目:请将你班学生的姓名与考试分数录入到Map中,并按分数从高到低在控制台上打印出来。
- c#例题:输入学生的学号,姓名,分数,然后根据分数进行排序再输出最终结果。重点学习用结构体定义数组的表达方式
- MySQL分组查询获取每个学生前n条分数记录(分组查询前n条记录)
- C#使用结构体,输入5个人的学号,姓名,分数,按照成绩高低排列打印出来
- 结构定义中元素位置排列问题
- 有五个学生,每个学生有3门课的成绩,定义一种比较直观的文本文件格式, 输入学生姓名和成绩,输入的格式:name,30,30,30从键盘输入以上数据(包括姓名,三门课成绩), 按总分数从高到低的顺序将学
- sql server 取每一个学生多个科目当中分数最高的记录……
- 编写一个Java应用程序,该程序包括3个类:定义一个学生类,Student有姓名,学号,选学的课程列表 ,定义一个课程类:课程名称,课程分数
- 定义一个学生类,有六个属性,一个打招呼的方法,一个计算自己总分数和平均分的方法
- 定义一个学生结构体类型struct student,里边含有学号,姓名,分数,定义结构体数组struct student s[3],给数组赋初值后, 写入文件,然后通过lseek偏移到开头,然后再读取
- 查询 数据库所有用户表 的记录,对分析数据库表的结构很有用,很方便,贴出来,备用!
- 建立一个学生结构数组来记录学生信息(学号ID,姓名和C语言成绩),要求动态建立一个结构数组,数组长度从键盘输入,自行给数组元素赋值并打印学生信息,最后不要忘记释放内存。 结构st