C语言修改

来源:百度知道 编辑:UC知道 时间:2024/05/29 13:50:12
帮我看一下子啊免得程序哪里出了问题~谢谢~
#include "Stdio.h"
#define N 5
void bubblesort(int x[])
{int i,j,t;
for(j=0;j<=N-2;j++)
{for(i=0;i<N-j-1;i++)
if(x[i]>x[i+1])
{t=x[i];x[i]=x[i+1];x[i+1]=t;}
}
}

search (int x[],int k,int s)
{int mid,top=x[0],bot=x[4];
s=-1;
while (top<=bot)
{mid=(top+bot)/2;
if(k==x[mid])
s=mid;
else if(k>x[mid])
top=mid+1;
else bot=mid-1;}
return s;
}

int main()
{
int i,n,b,c;
int a[N];
printf("please input 20 numbers:\n");
for (i=0;i<N;i++)
{scanf("%d",&a[i]);
printf("%5d",a[i]);}
printf("\n");
bubblesort(a);
printf("please input the number:\n");
scanf("%d",&b);
search(a,b,c);
if(c!=-1)
printf("The number is:%d,a[%d].\n",b,c);
else
printf("can't

还有问题没,一个问题100,我包了,呵呵

#include <Stdio.h>
#include<conio.h>
#define N 5
void bubblesort(int x[])
{
int i,j,t;
for(j=0;j<=N-2;j++)
{
for(i=0;i<N-j;i++) //<N-J就行,别加1
if(x[i]>x[i+1])
{
t=x[i];
x[i]=x[i+1];
x[i+1]=t;
}
}
}

void search (int x[],int k,int *s) //传递地址才能改变原来的变量
{
int mid,top=0,bot=N-1; //TOP和BOT是下标,不是其值
*s=-1;
while(top<=bot)
{
mid=(top+bot)/2;
if(k==x[mid]) //找到了就退出
{
*s=mid;
break;
}
else