1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
using namespace std;
int getsearchValue ();
void displayResults (int s, int o);
int search (int arr[], int size, int s);
const int SIZE = 5;
int main () {
int a[]= {10, 20, 40, 40, 50}, searchValue, occurs;
searchValue = getsearchValue;
occurs = search (a, SIZE, searchValue);
displayResults (searchValue, occurs);
return 0;
}
int getsearchValue () {
int input;
cout << "Enter searchValue: " ;
cin >> input;
return input;
}
void displayResults (int s, int o) {
cout << s << "occurs" << o << "times/n";
}
int search (int arr[], int size, int s) {
int count = 0;
for (int i = 0; i < size && s >= arr[i]; i++)
if (s == arr[i])
count++;
}
|