1.程序如下:
#include
void main()
{ int a[100];
int i,n,m;
printf("请输入数备源组元素个数");
scanf("%d",&n);
printf("请输入数组元素(各元素之间用enter键):");
for(i=0;i scanf("%d",&a[i]);
printf("请输入要查找的数");
scanf("%d",&m);
for(i=0;i<=n;i++)
if(a[i]==m)
printf("该数的下标:%d\n",i);
if(i>=n) printf("%d",-1);
}
2.程序如下:
#include
#include
void main()
{
void sort(char *name[],int n);
void print(char 誉滚敬*name[],int n);
char *name[]={"Bejing","Shanghai","Shenzhen","Nanjing","Dalian"庆慎,"Qingdao"};
int n=6;
sort(name,n);
print(name,n);
}
void sort(char *name[],int n)
{
char *temp;
int i,j,k;
for(i=0;i {k=i;
for(j=i+1;j if(strcmp(name[k],name[j])>0)k=j;
if(k!=i)
{temp=name[i];name[i]=name[k];name[k]=temp;}
}
}
void print(char *name[],int n)
{
int i;
for(i=0;i printf("%s\n",name[i]);
}