【50分】c语言程序优化

来源:百度知道 编辑:UC知道 时间:2024/09/28 15:12:17
职工管理系统
该系统的功能包括输入、排序、查找。主程序中包括3个函数其中input()函数的功能是:输入职工的姓名和职工号。sort()函数的功能是:按职工号由小到大排序,姓名顺序也随之调整。search()函数的功能是:根据主函数提供的职工号进行查找,若找到该职工则输出对应职工的姓名,若找不到则输出“not find”。
#include"stdio.h"
#include"string.h"
#define NUMMAX 100
void input(int a[],char b[][20],int n)
{
int i;
for(i=0;i<n;i++)
{
a[i]=i+1;
printf("please input No.%d worker's name:\n",i+1);
scanf("%s",&b[i][20]);
}
}
void sort(char name[][20],int n)
{
int i;
for(i=0;i<n;i++)
printf("No.%d worker's name:%s\n",i+1,name[i][20]);
}
void search(int n,char name[][20],int number)
{
if(number<=n)
printf("the worker you find is:%s\n",name[number][20]);
else
printf("not find\n");
}
main()
{
char c;
int num[NUMMAX];
char name[NUMMAX][20];
int n,fl

int num[NUMMAX]; 这个在程序中没用上,可以去掉
另外你这里sort()只是实现了按序输出功能,根本不涉及排序

初始输入数假如超过NUMMAX的话,会溢出
还是加入一个循环判断吧,假如不超过就继续,超过就重新输入

还有不清楚你想优化什么,想怎么优化……