C++ program to implement linear search in unsorted array

Suman Barik
0

#include <bits/stdc++.h>


using namespace std;


int func(int math[], int a, int b){


  for(int i = 0; i < a; i++)

  

    if(math[i] == b)

    

      return i;


      return -1;


}


int main(){


  int math[] = {23,45,14,85};

  

  int a = sizeof(math) / sizeof(int);

  

  int b = 45;

  

  int position = func(math, a, b);

  

  if(position == -1)

  

    cout << "Element not found";

  

    cout << "Elements found at : " << position + 1;

    

  return 0;

  

}

  

  


  

  

Tags

Post a Comment

0Comments
Post a Comment (0)