寻找离边界最近的0
#include<stdio.h>#include<stdlib.h>
#include<time.h>
int find_zero(int a[],int n)
{
int * p = NULL;
int * q = NULL;
p = a;
q = a + n -1;
while(p <= q)
{
if(*p == 0)
{
return p-a;
}
if(*q == 0)
{
return q-a;
}
p++;
q--;
}
printf("NO zero!\n");
return -1;
}
int main(void)
{
int a[20] = {0};
int * p = a;
srand(time(NULL));
do{
*p = rand()%20;
printf("%3d",*p);
p++;
}while(p < a+19 );
printf("\n");
printf("%d\n",find_zero(a,20));
return 0;
}
求大神指点啊,怎么错了,感觉没有运行,返回值是错的