nly write a function that receives an array, its size and a value to search for (define your function in the same way as the given function prototype). The function should return the index of the searched element in the array. If the element is not found, it should return -1. If the array has more than one element of that same value, it should return the value -2. The array is not necessarily sorted and should not be sorted in the function. #include #include int searchIt(int arr[], int size, int value); int main() { int a[]={1,2,3,4,5}; printf("%d", searchIt(a,5,3)); return 0; } //Your answer starts here. For example: Test Result int a[]={1,2,3,4,5}; printf("%d", searchIt(a,5,3)); 2 int b[]={3,2,5,7,10,2,4}; printf("%d", searchIt(b,7,2)); -2 int c[]={-1,0,234,43,2,1,4,5}; printf("%d", searchIt(c,8,99)); -1

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.1: Function And Parameter Declarations
Problem 13E
icon
Related questions
Question

C codeblocks

Only write a function that receives an array, its size and a value to search for (define your function in the same way as the given function prototype). The function should return the index of the searched element in the array. If the element is not found, it should return -1. If the array has more than one element of that same value, it should return the value -2. The array is not necessarily sorted and should not be sorted in the function.

#include <stdio.h>
#include <stdlib.h>

int searchIt(int arr[], int size, int value);

int main() {
int a[]={1,2,3,4,5};
printf("%d", searchIt(a,5,3));
return 0;
}

//Your answer starts here.

For example:

Test Result
int a[]={1,2,3,4,5}; printf("%d", searchIt(a,5,3)); 2
int b[]={3,2,5,7,10,2,4}; printf("%d", searchIt(b,7,2)); -2
int c[]={-1,0,234,43,2,1,4,5}; printf("%d", searchIt(c,8,99)); -1

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning