线性搜索

一、问题:线性搜索某个数是否存在。

二、代码

#include <iostream>
using namespace std;


int main()
{
    int A[] = { 9, 2, 8, 6, 7, 1, 4, 5, 3, 0 };
    int target=11;
    bool found = false;
    for (int i = 0; i < 10; i++)
    {
        if (target == A[i])
        {
            cout << "I have found it. The num is:" << i;
            found = true;
            break;
        }
    }
    if (found == false)
    {
        cout << "sorry! i can not found it!";
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Wanggcong/p/4705383.html