1.在一个已排序的整形数组中,插入一个数,使之仍然有序.
2.定义一个二维数组,存储5个人的姓名和电话号码,从键盘输入姓名后,要求能输出电话号码。
[此贴子已经被作者于2007-5-11 19:59:37编辑过]
后边有的!!!!!!!
#include <stdio.h>
main()
{
int a[5]={1,2,3,4,5};/*那个已经排序的*/
int b[6];
int c,i,j,n;
scanf("%d",&c);
for(i=4;i>0;i--)
{
if(c>=a[i])
{
j=i;
break;
}
}
for(i=0;i<=j;i++)
b[i]=a[i];
n=5;
for(i=4;i>j;i--)
b[n--]=a[i];
b[j+1]=c;
for(i=0;i<6;i++)
printf("%d ",b[i]);
getch();
}
#include<stdio.h>
#define N 11
void getin(int *,int);
void main()
{
int a[N]={1,5,10,17,24,28,32,35,46,70},x,i;
printf("input the number which you want putinto a[11] x:");
scanf("%d",&x);
getin(a,x);
for(i=0;i<N;i++)printf("%d ",a[i]);
}
void getin(int *a,int x)
{
int i,m;
for(i=0;i<N-1;i++)if(a[i]<=x&&x<=a[i+1])m=i+1;
for(i=N-1;i>m;i--)a[i]=a[i-1];
a[m]=x;
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#define N 10
void main()
{
char a[N][N]={{"yaoming"},{"586947"},{"xiexun"},{"971836"},{"xiexiao"},{"68754812"},{"shen"},{"5418796"},{"god"},{"825547"}};
char b[N];
int R,i;
printf("whose' number do you want to find,if you want exit input exit:");
scanf("%s",b);
while(fabs(strcmp("exit",b)))
{
R=0;
for(i=0;i<N;i+=2)
{
R=strcmp(a[i],b);
if(R==0)
{
puts(a+i+1);
break;
}
}
printf("whose' number do you want to find,if you want exit input exit:");
scanf("%s",b);
}
getch();
}