-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a C++ program for linear search in an array
- Loading branch information
1 parent
1c7fdcf
commit 71d4e29
Showing
1 changed file
with
15 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |