您的位置:首页 > 其它

搜索问题(查找X是否在数据中)

2011-11-20 10:31 253 查看
问题:

查找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
= {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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐