顺序查找
来源:互联网 发布:淘宝上levis眼镜 编辑:程序博客网 时间:2024/05/02 17:26
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int SequentialSearch(int a[], int n, int x)
{
int i;
for (i = 0; i < n; i++)
{
if (x == a[i])
{
return i;
}
}
return -1;
}
int main()
{
int x, result;
int a[10] = { 2, 4, 6, 8, 0, 1, 3, 5, 7, 9 };
printf("请输入你要查找的数:");
scanf("%d", &x);
result = SequentialSearch(a, 10, x);
if (result==-1)
{
printf("没有找到。\n");
}
else
{
printf("在a[%d]里找到%d\n", result, x);
}
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int SequentialSearch(int a[], int n, int x)
{
int i;
for (i = 0; i < n; i++)
{
if (x == a[i])
{
return i;
}
}
return -1;
}
int main()
{
int x, result;
int a[10] = { 2, 4, 6, 8, 0, 1, 3, 5, 7, 9 };
printf("请输入你要查找的数:");
scanf("%d", &x);
result = SequentialSearch(a, 10, x);
if (result==-1)
{
printf("没有找到。\n");
}
else
{
printf("在a[%d]里找到%d\n", result, x);
}
system("pause");
return 0;
}
0 0
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 顺序查找
- 【顺序查找】
- Linux入门学习教程:在Ubuntu 14.04中安装使用搜狗拼音输入法
- 计算机独立本科考试
- python---通过networkx使图着色结果可视化
- day07—SQL基本查询
- hdu4565 矩阵构造+矩阵快速幂
- 顺序查找
- window下连接ubuntu mysql的问题
- 【PAT】1044. 火星数字(20)
- 数论+差分 hdu1121 Complete the Sequence
- js 函数 function
- java基础总结第一篇(JAVA简介)
- ios中navigation controller的漂移问题
- JVM学习笔记9—JIT及其相关参数
- Hello World——CSDN Blog