搜索问题(查找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;
}
查找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;
}
相关文章推荐
- 位图法--解决海量数据问题(查找是否存在,不重复数据)
- 在excel中查找某列内容中是否有重复数据
- 解决mysql的select查找的数据出现乱码的问题
- 分治思想 - 二分搜索技术 - MATLAB代码 list是数据集合,x是要查找的数据。
- 在gae后台判断数据是否存在 实体的ID DateTime时区的问题
- 每日学习总结:DropDownList是否已选择验证、存储过程参数为sql字符串问题、将截断字符串或二进制数据。\r\n语句已终止
- ExtJs3.2和ExtJs3.0在reload时的区别(点击左边树的节点时右边表格中的数据是否同步的问题)
- [recv][网页][数据]recv到网页数据的查找问题
- 数据结构复习——链栈的一些操作以及表达式中的括号是否配对问题
- 用ajax的同步请求解决登陆注册需要根据服务器返回数据判断是否能提交的问题
- filter()的参数内容,查找语句。其中in可以在一个结果集中查找是否包含另一个结果集的数据。
- 程序员编程艺术:第二章、字符串是否包含及匹配/查找/转换/拷贝问题
- 调试问题:datatables进行搜索后,再次按下分页,表格数据无法改变
- 数据结构——算法之(011)( 字符串是否包含问题)
- 论文数据查找和论文参考准确搜索定位
- 关于mongodb查询数据,数值类型查找不到数据的问题
- 从数据库读取text属性数据,并比较内容是否相等的问题。
- 解决大批数据判断是否素数及位置的问题
- 运用数据库来实现数据分页以及搜索问题
- 转:[大数据竞赛]协同过滤在这个问题上是否work