我的一个 C语言代码
2006-11-01 12:15
429 查看
#include<stdio.h>
struct student
{
int num;
char name[15];
int score[3];
double avr;
};
struct student stu[50];
struct student input();
void display(struct student stud[],int count);
void sort(struct student stud[],int count);
void insert(struct student stud[],int count);
void del(struct student stud[],int count);
void main()
{
int count=0;
char ch='y';
while((ch=='y')||(ch=='Y'))
{
stu[count]=input();
count++;
fflush(stdin);
printf("/n是否继续?(y or n)");
scanf("%c",&ch);
}
display(stu,count);
}
struct student input()
{
struct student studn;
int sum,j;
printf("/n学号:");
scanf("%d",&studn.num);
printf("/n姓名:");
scanf("%s",&studn.name);
printf("/n三门成绩:");
sum=0;
printf("/n");
for(j=0;j<3;j++)
{
printf("成绩%d:",j+1);
scanf("%d",&studn.score[j]);
sum+=studn.score[j];
}
studn.avr=sum/3.0;
return studn;
}
void display(struct student stud[],int count)
{
printf("/n学号/t姓名/t/t平均成绩/n");
for(int i=0;i<count;i++)
{
printf("%-0.3d",stud[i].num);
printf("/t%-15s",stud[i].name);
printf("/t%-10.1f",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[i];
stud[i]=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[i];
}
stud[i]=temp;
}
void del(struct student stud[],int count)
{
int dno,i;
struct student temp;
printf("/n请输入要删除学员的学号:");
scanf("%d",&dno);
for(i=0;i<count;i++)
{
if(stud[i].num==dno);
break;
}
for(int j=i;j<count-1;j++)
{
stud[j+1]=stud[i];
}
}
struct student
{
int num;
char name[15];
int score[3];
double avr;
};
struct student stu[50];
struct student input();
void display(struct student stud[],int count);
void sort(struct student stud[],int count);
void insert(struct student stud[],int count);
void del(struct student stud[],int count);
void main()
{
int count=0;
char ch='y';
while((ch=='y')||(ch=='Y'))
{
stu[count]=input();
count++;
fflush(stdin);
printf("/n是否继续?(y or n)");
scanf("%c",&ch);
}
display(stu,count);
}
struct student input()
{
struct student studn;
int sum,j;
printf("/n学号:");
scanf("%d",&studn.num);
printf("/n姓名:");
scanf("%s",&studn.name);
printf("/n三门成绩:");
sum=0;
printf("/n");
for(j=0;j<3;j++)
{
printf("成绩%d:",j+1);
scanf("%d",&studn.score[j]);
sum+=studn.score[j];
}
studn.avr=sum/3.0;
return studn;
}
void display(struct student stud[],int count)
{
printf("/n学号/t姓名/t/t平均成绩/n");
for(int i=0;i<count;i++)
{
printf("%-0.3d",stud[i].num);
printf("/t%-15s",stud[i].name);
printf("/t%-10.1f",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[i];
stud[i]=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[i];
}
stud[i]=temp;
}
void del(struct student stud[],int count)
{
int dno,i;
struct student temp;
printf("/n请输入要删除学员的学号:");
scanf("%d",&dno);
for(i=0;i<count;i++)
{
if(stud[i].num==dno);
break;
}
for(int j=i;j<count-1;j++)
{
stud[j+1]=stud[i];
}
}
相关文章推荐
- C语言 求一个数二进制码中1的个数 最短代码
- 一个类似ifconfig功能的程序代码--C语言
- 用C语言开发一个BT下载软件 (四) ------ 代码实现-1-种子文件解析模块
- (一个代码学会c语言操作数据库)linux上通过c语言操作数据库实现基本的学生信息管理系统(增、删、查、改‘显示)
- C-发布一个关于数据结构的C语言代码
- 【C语言】编写代码实现:求一个整数在内存中的二进制位中1的个数
- 以下是在网上看到的一个用C语言编写的木马源程序代码大家
- 一个超复杂的间接递归——C语言初学者代码中的常见错误与瑕疵(6)
- 一个正确的c语言链表代码(中间也有些bug)
- 对于C语言面向对象封装性的改进尝试——基于一个简易计算器的代码
- C-055.自己用C语言写的一个正整数的十进制转二进制的代码
- 用C语言开发一个BT下载软件 (四) ------ 代码实现-5-Peer管理模块
- 写一个程序,统计自己C语言共写了多少行代码,Github基本操作
- 请大家看一下一个c语言中的链表问题,下面的代码是有错误的!!请大家说出错误的原因,以及修改的方法!!!
- c语言中如何把一个文件中的内容复制到另外一个文件中的代码
- 图论:一个叫做SPFA的东西(C语言代码实现)
- c语言实现一个单元测试框架(Unit Test Framework)代码
- 用C语言编写一个去除C代码中所有的注释的部分
- 用C语言实现一个简单的计算器代码
- 【C语言】通讯录代码(一个文件下实现)