有n个学生的信息(包括学号、姓名、成绩),要求按照成绩的高低顺序输出各学生的信息。
2013-03-20 10:07
981 查看
/*
============================================================================
Name : C12.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
struct Student {
int stuid;
char name[30];
float score;
};
int main(void) {
//初始化结构体
struct Student stu[5] =
{ { 10101, "aaa", 37 }, { 10101, "bb", 67 },
{ 10103, "liming", 34 }, { 10104, "lixiao", 78 }, { 10105,
"ccc", 45 } };
struct Student temp;
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4 - i; j++) {
if (stu[j].score > stu[j + 1].score) {
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
//输出结构体的内容
for (i = 0; i < 5; i++) {
printf("第%d个学生信息:学号:%d,姓名:%s成绩:%.2f\n", i+1,stu[i].stuid, stu[i].name,
stu[i].score);
}
return EXIT_SUCCESS;
}
============================================================================
Name : C12.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
struct Student {
int stuid;
char name[30];
float score;
};
int main(void) {
//初始化结构体
struct Student stu[5] =
{ { 10101, "aaa", 37 }, { 10101, "bb", 67 },
{ 10103, "liming", 34 }, { 10104, "lixiao", 78 }, { 10105,
"ccc", 45 } };
struct Student temp;
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4 - i; j++) {
if (stu[j].score > stu[j + 1].score) {
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
}
}
}
//输出结构体的内容
for (i = 0; i < 5; i++) {
printf("第%d个学生信息:学号:%d,姓名:%s成绩:%.2f\n", i+1,stu[i].stuid, stu[i].name,
stu[i].score);
}
return EXIT_SUCCESS;
}
相关文章推荐
- 有n个学生的信息(包括学号,姓名,成绩),要求按照成绩的高低顺序输出学生的信息
- 有n个学生的信息(包括学号,姓名,成绩),要求按照成绩的高低顺序输出学生的信息
- 【C语言】用结构体数组完成:有5个学生(包括学号,姓名,成绩),要求按照成绩高低输出学生信息.
- 例 9.7 有n个结构体变量,内含学生学号、姓名和3门课程的成绩。要求输出平均成绩最高的学生的信息(包括学号、姓名、3门课程成绩和平均成绩)。
- 扩展练习4(学生类设计).设计一个友元函数,按照成绩从高到低的顺序输出姓名、学号和成绩信息
- [4.21]编写一个程序,已有若干个学生的数据,包括学号、姓名、成绩、要求输出这些学生的数据并计算出学生人数和平均成绩(要求将学生人数和总成绩用静态数据成员表示)。
- Student类,包括学生姓名、性别、年龄、Java成绩。要求创建五个该类对象,输出每个学生信息,计算并输出这五个学生Java成绩的平均值, 以及计算并输出他们Ja
- 习题 9.5 有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。
- 字符串数组 输入3个字符串,要求按由小到大的字母顺序输出; 输入n个学生的姓名和学号到字符串数组中,在输入一个姓名,如果班级有该生则返回其信息,否则返回本班无此人
- 输入N个学生的信息(包括:学号,姓名,5科成绩,总分),统计所有学生的总分,存入二进制文件stu_sc.dat中。然后读取该文件,查找总分最高的学生,并输出该生的所有信息。
- 有五个学生,每个学生有3门课的成绩, 从键盘输入以上数据(包括姓名,三门课成绩), 输入的格式:如:zhagnsan,30,40,60计算出总成绩, 并把学生的信息和计算出的总分数高低顺序存放在磁盘文
- 1061 有N个学生的数据,将学生数据按成绩高低排序,如果成绩相同则按姓名字符的字母序排序,如果姓名的字母序也相同则按照学生的年龄排序,并输出N个学生排序后的信息。
- 有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩。读入这10个学生的数据,要求输出3门课程的总平均成绩,以及个人平均分最高的学生的数据
- (指向结构体数组的指针)有n个结构体变量,内含学生学号,姓名和3门课的成绩。要求输出平均成绩最高的学生的信息
- 编写一个程序,已有若干学生的数据,包括学号,姓名,成绩,要求输出这些学生的数据并计算出学生人数和平均成绩
- c语言:用结构体变量输出学生的信息,包括学号,姓名,性别。
- PHP之键盘输入四个学生的学号 姓名 语文 数学 英语信息 ,计算出每个学生的平均成绩,输出
- 创建一个学生类(Student),包括学号成绩,编程输入和显示学生的信息。建立一个人类(Person),包含姓名、性别和年龄,并作为学生类的基类
- 27.有10个学生,输出成绩最低的学生的信息(包括姓名、年龄、成绩、出生日期)(用结构体知识)。
- 建立一个学生结构数组来记录学生信息(学号ID,姓名和C语言成绩),要求动态建立一个结构数组,数组长度从键盘输入,自行给数组元素赋值并打印学生信息,最后不要忘记释放内存。 结构st