Computer Science, asked by kylecabato28, 6 months ago

TASK 14:
Direction: Given an array of n elements, write a function to
search a given elementx in array. Kindly write your answer in a
short bond paper.
Input: array= {10, 20, 80, 30, 60, 50,
110, 100, 130, 170}
x = 110,
Output: 6
Elements is present at index 6
Input: array = {10, 20, 80, 30, 60, 50,
110, 100, 130, 170
x = 175;
Output: -1
Elements is not present in array.​

Answers

Answered by Anonymous
0

Answer:

Falcons are birds of prey in the genus Falco, which includes about 40 species. Falcons are widely distributed on all continents of the world except Antarctica, though closely related raptors did occur there in the Eocene

Answered by ParvezShere
0

A function to search a given element in array:

int search(int array[], int n, int x) {

 for (int i = 0; i < n; i++)

   if (array[i] == x)

     return i;

 return -1;

}

int main() {

 int array[] = {10, 20, 80, 30, 60, 50,110, 100, 130, 170};

 int x;

 cin>>x;

 int result = search(array, n, x);

 cout << result;

}

#SPJ3

Similar questions