//There is a simple program that will process the linear search algorithm.
#include <iostream>

using namespace std;

int main()
{
    int n;
    cout << "How many numbers:";
    cin >> n;
    int a[n],number;
    bool c = true;

    for(int i = 0;i < n;i++)
        cin >> a[i];

    cout << "Which number do you want to search:";
    cin >> number;

    for(int i = 0;i < n;i++)
    {
        if(a[i] == number)
        {
            cout << "Found\n";
            c = false;
            break;
        }
    }

    if(c)
        cout << "Not Found\n";

    return 0;
}

No comments:

Post a Comment

Kruskal Algorithm

Minimum Cost Spanning Tree By Kruskal Algorithm using priority_queue in c++ #include<bits/stdc++.h> using namespace std; typedef p...