linear search in array

 #include <iostream>

using namespace std;
bool search(int arr[], int size, int key){
for (int i = 0; i < size; i++)
{
if (arr[i]==key)
{
return 1;
}
}
return 0;
}
int main(){

int arr[10]={1,2,3,4,5,6,7,8,9,10};

int key;
cout<<"plz enter the key to search of : ";;
cin>>key;

bool found = search(arr,10,key);

if (found)
{
cout<<"Yes it is present!";
}
else {
cout<<" No It is Absent "<<endl;
}





}



Comments

Popular posts from this blog

swapping the alternate values in given array's element ! 17/11/2022

Learning stage | c++ programs

c++ basic question