问题:
查找X是否在数组中?
#include <stdio.h>
#define N 10
#define X 88
int Search(int a[], int n, int x)
{
int i = 0;
while (i < n)
{
if (x == a[i])
return i;
i++;
}
return -1;
}
int main(void)
{
int a[N] = {12, 34, 56, 78, 54, 82, 124, 90, 456, 88};
int x = X;
int j = 0;
j = Search(a, N, x);
if (j == -1)
{
printf("%d is not exist\n", x);
}
else
{
printf("%d is the number %d\n", x, j+1);
}
return 0;
}