Untitled
unknown
plain_text
8 days ago
511 B
1
Indexable
Never
#include <iostream> #include <ctime> #include <array> #include <string> using namespace std; int linearSearch(int array[], int length, int x){ for (int i = 0; i <= length; i++){ if (array [i] == x){ cout << i; } } return -1; } int main() { int array1[] = {1, 2, 3, 4, 5}; int length = sizeof(array1); int yourNum; cout << "Enter a number: "; cin >> yourNum; linearSearch(array1,length, yourNum); }
Leave a Comment