diff --git a/LinearSearch b/LinearSearch new file mode 100644 index 0000000..4a55551 --- /dev/null +++ b/LinearSearch @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main(){ + int input[100], count, i, num; + + cout << "Enter Number of Elements in Array\n"; + cin >> count; + + cout << "Enter " << count << " numbers \n"; + + // Read array elements + for(i = 0; i < count; i++){ + cin >> input[i]; + } + + cout << "Enter a number to serach in Array\n"; + cin >> num; + + // search num in inputArray from index 0 to elementCount-1 + for(i = 0; i < count; i++){ + if(input[i] == num){ + cout << "Element found at index " << i; + break; + } + } + + if(i == count){ + cout << "Element Not Present in Input Array\n"; + } + + return 0; +}