我的编程生涯的入门语言 - C语言之学员成绩管理
2012-03-10 17:48 音乐让我说 阅读(339) 评论(0) 编辑 收藏 举报至今还保存着当初学 C语言 时的代码,现在看来已经有点生疏,毕竟好久没玩了。
往事不堪回首啊!
直接贴代码了:
#include <stdio.h> struct student { int num; char name[15]; float score[3]; double avr; }; struct student stu[50]; struct student input() { struct student studn; int i,sum=0; printf ( "请输入学号:" ); scanf ( "%d" ,&studn.num); printf ( "请输入姓名:" ); scanf ( "%s" ,&studn.name); for (i=0;i<3;i++) { printf ( "第%d 个成绩:" ,i+1); scanf ( "%f" ,&studn.score[i]); sum+=studn.score[i]; } studn.avr=sum/3.0; return studn; } void display( struct student stud[], int count) { printf ( "\n学号\t姓名\t平均成绩\n" ); for ( int i=0;i<count;i++) { printf ( "%d" ,stud[i].num); printf ( "\t%s" ,stud[i].name); printf ( "\t%7.2f" ,stud[i].avr); printf ( "\n" ); } } void sort ( struct student stud[], int count) { struct student t; for ( int i=0;i<count;i++) { for ( int j=0;j<count-i-1;j++) { if ((stud[j].avr)<(stud[j+1].avr)) { t=stud[j]; stud[j]=stud[j+1]; stud[j+1]=t; } } } } void insert ( struct student stud[], int count) { int i,j; struct student temp; printf ( "请输入要插入学员的信息\n" ); temp = input(); for (i=0;i<count;i++) { if ((stud[i].avr)<(temp.avr)) break ; } for (j=count;j>=i;j--) { stud[j+1]=stud[j]; } stud[i]=temp; } void display2( struct student stud[], int count) { printf ( "\n学号\t姓名\t平均成绩\n" ); for ( int i=0;i<(count+1);i++) { printf ( "%d" ,stud[i].num); printf ( "\t%s" ,stud[i].name); printf ( "\t%7.2f" ,stud[i].avr); printf ( "\n" ); } } void dele ( struct student stud[], int count ) { int i,j,temp; //struct student temp; printf ( "请输入要删除的学员的学号:\n" ); scanf ( "%d" ,&temp); // temp=input(); for (i=0;i<count;i++) { if (stud[i].num==temp) { for (j=i;j<count;j++) { stud[j]=stud[j+1]; } } } } void main() { int count=0; char ch= 'Y' ; while ((ch== 'y' )||(ch== 'Y' )) { stu[count]=input(); count++; printf ( "是否要继续(y/n):\n" ); fflush (stdin); scanf ( "%c" ,&ch); } printf ( "\n排序前的学员成绩序列如下:" ); display(stu,count); sort (stu,count); printf ( "排序后的学员成绩序列如下:" ); display (stu,count); insert(stu,count); printf ( "插入后的学员成绩序列如下:" ); display2 (stu,count); dele(stu,count+1); display (stu,count); } |
谢谢浏览!
作者:音乐让我说(音乐让我说 - 博客园)
出处:http://music.cnblogs.com/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
2011-03-10 数据库打开程序.bat
2011-03-10 一个简单的递归面试题