学了结构体用结构体能实现。
#include<stdio.h>
struct Staff{
char name[20];
double num;
};
int main()
{
int i,j, p=0;
double key;
struct Staff temp;
struct Staff staff[10]={{"郑海兵",201003020076},
{"宋天琪",20100302001},
{"宋 健",201003020077},
{"李丹丹",201003020054},
{"马 文",201003020090},
{"孙家林",201003020017},
{"王 昆",201003020012},
{"段华鹏",201003020040},
{"小 六",201003020080},
{"李 勇",201003020069}};
for(i=0;i<10;i++)
printf("%s %.0lf\n",staff[i].name,staff[i].num);
for(j=0;j<10;j++)
for(i=0;i<9-j;i++)
if(staff[i].num>staff[i+1].num){
temp=staff[i];
staff[i]=staff[i+1];
staff[i+1]=temp;
}
for(i=0;i<10;i++)
printf("从小到大输出:%s %.0lf\n",staff[i].name,staff[i].num);
while(p==0){
printf("input a staff's number:\n");//折半查找???
scanf("%f",&key);
for(i=0;i<10;i++)
if(key==staff[i].num)
{
printf("%s %.0lf",staff[i].name,staff[i].num);
p=1;
}
else{
}
if(p=0)
printf("输入有误,重新出入!\n");
}
return 0;
}
谢谢各位!
#include<stdio.h>
struct Staff{
char name[20];
double num;
};
int main()
{
int i,j, p=0;
double key;
struct Staff temp;
struct Staff staff[10]={{"郑海兵",201003020076},
{"宋天琪",20100302001},
{"宋 健",201003020077},
{"李丹丹",201003020054},
{"马 文",201003020090},
{"孙家林",201003020017},
{"王 昆",201003020012},
{"段华鹏",201003020040},
{"小 六",201003020080},
{"李 勇",201003020069}};
for(i=0;i<10;i++)
printf("%s %.0lf\n",staff[i].name,staff[i].num);
for(j=0;j<10;j++)
for(i=0;i<9-j;i++)
if(staff[i].num>staff[i+1].num){
temp=staff[i];
staff[i]=staff[i+1];
staff[i+1]=temp;
}
for(i=0;i<10;i++)
printf("从小到大输出:%s %.0lf\n",staff[i].name,staff[i].num);
while(p==0){
printf("input a staff's number:\n");//折半查找???
scanf("%f",&key);
for(i=0;i<10;i++)
if(key==staff[i].num)
{
printf("%s %.0lf",staff[i].name,staff[i].num);
p=1;
}
else{
}
if(p=0)
printf("输入有误,重新出入!\n");
}
return 0;
}
谢谢各位!