Skip to content

Commit

Permalink
Update LinearSearch.cpp
Browse files Browse the repository at this point in the history
Add a C++ program for linear search in an array
  • Loading branch information
sulaemanahmed authored Nov 1, 2023
1 parent 1c7fdcf commit 71d4e29
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Add Code Here/C++/Arrays/LinearSearch.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#include <iostream>
using namespace std;
int main(){
int A[10] = {10,512,8,82,8,55,44,55,45,45}, key;

int main() {
int A[10] = {10, 512, 8, 82, 8, 55, 44, 55, 45, 45};
int key;

cout << "Enter Key: ";
cin >> key;
for(int i =0; i< 10 ; i++){

if (key == A[i]){
cout << "Found at " << i << endl;
return 0;
}
for (int i = 0; i < 10; i++) {
if (key == A[i]) {
cout << "Found at index " << i << endl;
return 0;
}
}
cout << "Jane de n vro!";
}

cout << "Key not found!" << endl;

return 0;
}

0 comments on commit 71d4e29

Please sign in to comment.