Question

Write a C++ function definition for a function called searchList, which has an integer array parameter....

  1. Write a C++ function definition for a function called searchList, which has an integer array parameter. The function should search the array for an input value which is passed as a parameter variable. If the input value is located in the array, the function should return the index number of the array element. If the value is not found, the function should return -1. Make sure to add any other function parameters that are needed.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
int searchList(int arr[], int size, int target) {
    for (int i = 0; i < size; ++i) {
        if (arr[i] == target) {
            return i;
        }
    }
    return -1;
}
Add a comment
Know the answer?
Add Answer to:
Write a C++ function definition for a function called searchList, which has an integer array parameter....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT