From 71d4e293df17df9735d4a0e64087b40197fab8e0 Mon Sep 17 00:00:00 2001 From: sulaemanahmed <132727787+sulaemanahmed@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:23:26 -0500 Subject: [PATCH] Update LinearSearch.cpp Add a C++ program for linear search in an array --- Add Code Here/C++/Arrays/LinearSearch.cpp | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Add Code Here/C++/Arrays/LinearSearch.cpp b/Add Code Here/C++/Arrays/LinearSearch.cpp index 1687c1da0f3..e27ffdc84ae 100644 --- a/Add Code Here/C++/Arrays/LinearSearch.cpp +++ b/Add Code Here/C++/Arrays/LinearSearch.cpp @@ -1,15 +1,21 @@ #include 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!"; -} \ No newline at end of file + + cout << "Key not found!" << endl; + + return 0; +}