主函数创建5个学生的数组,写一个排序函数,让学生按姓名从小到大排序,主函数输出排序后的结果
2014-07-28 21:24
363 查看
//1.主函数创建5个学生的数组,写一个排序函数,让学生按姓名从小到大排序,主函数输出排序后的结果。 void sortStuByName(Student *pStu, int count) { for (int i = 0; i < count - 1; i++) { for (int j = 0; j < count - 1 - i; j++) { if (strcmp((pStu + j)->name, (pStu + j + 1)->name) > 0) { char temp[20] = {0}; strcpy(temp, pStu + j + 1); strcpy(pStu + j + 1, pStu + j); strcpy(pStu + j, temp); } } } } void outputStu(Student *pStu, int count) { for (int i = 0; i < count; i++) { printf("%s %d %d\n", (pStu + i)->name, (pStu + i)->age, (pStu + i)->score); } } //2、写一个整型数组排序的函数,并测试效果。 void assignArr(int *pArr, int count) { for (int i = 0; i < count; i++) { *(pArr + i) = arc4random() % 50; } } void sortArr(int *pArr, int count) { for (int i = 0; i < count - 1; i++) { for (int j = 0; j < count - 1 - i; j++) { if (*(pArr + j) > *(pArr + j + 1)) { int temp = *(pArr + j + 1); *(pArr + j + 1) = *(pArr + j); *(pArr + j) = temp; } } } } void outputArr(int *pArr, int count) { for (int i = 0; i < count; i++) { printf("%d ", *(pArr + i)); } }
相关文章推荐
- 主函数创建5个学生的数组,写一个排序函数,让学生按姓名从小到大排序,主函数输出排序后的结果。
- //1.主函数创建5个学生的数组,写一个排序函数,让学生按姓名从小到大排序,主函数输出排序后的结果。
- (C语言-结构体)主函数创建5个学生的数组,写一个排序函数,让学生按姓名从小到大排序,主函数输出排序后的结果。
- 要求从用户输入的多行文本中提取学生的姓名、学号及登录日期,并封装到 Student 类中作为类的私有属性。创建一个Student类型的对象数组,对学号进行 升序排序并输出。
- 要求从用户输入的多行文本中提取学生的姓名、学号及登录日期,并封装到 Student 类中作为类的私有属性。创建一个 Student 类型的对象数组,对学号进行 升序排序并输出
- c#例题:输入学生的学号,姓名,分数,然后根据分数进行排序再输出最终结果。重点学习用结构体定义数组的表达方式
- 个有10个元素的整型一维数组,用户输入9个数据,调用函数,对数组元素进行从小到大排序后,在函数中输入一个数,插入到数组中正确的位置,并输出
- 编写一个函数print,打印一个学生的成绩数组,该书组中有五个学生的数据,每个学生的数据包括num(学号)、name(姓名)、score(3门课的成绩)、用主函数输入这些数据,用print函数输出这些
- 习题 9.3 编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些记录,用print函数输出这些记录。
- 建立一个对象数组,内放5个学生的数据(学号,成绩),用指向对象的指针做函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。
- 创建一个字符串数组,总共5个元素,每个元素最多保存30个字符,写一个函数排序整个数组。
- 创建一个字符串数组,总共5个元素,每个元素最多保存30个字符,写一个函数排序整个数组。
- 在一个长度为10的整型数组里面,保存了班级10个学生的考试成绩。要求编写5个函数,分别实现计算考试的总分,最高分,最低分,平均分和考试成绩降序排序
- Chapter9——建立一个对象数组,内放5个学生的数据(学号,成绩),设立一个函数max,用指向对象的指针做函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。
- 建立一个对象数组,内放5个学生数据(学号、成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并从输出学号。
- 建立一个动态数组,输入5个学生的成绩,另外用一个函数检查其中有无低于60分的,输出不合格的成绩
- 'VB编程 编写一个竞赛评分的函数过程。评委打分为参数(数组参数),选手得分为函数值。记分规则为:去掉一个最高分,去掉一个最低分,然后求平均。调用该函数,由键盘输入5个评委的打分(存放在数组中),输出
- 黑马程序员---------------------声明类Students,包含3个成员变量:name、age、score,创建5个对象装入TreeSet,按照成绩排序输出结果(考虑成绩相同的问题)。
- 编写一个函数,由实参传来一个字符串,统计此字符串中字母,数字,空格,和其他字符的个数,在主函数中输入字符串以及输出上述统计的结果。再考虑将算的的结果放在一个数组中
- 【OC复合题】之定义一个学生类,需要有姓名,年龄,考试成绩三个成员属性,创建5个对象,属性可以任意值。(Objective-C)