lab18 - array is not a concern here, so I'll provide you...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 18: Searching an Array Last Modified 03/08/2009 Key Concepts: arrays and methods, search Write a function that takes in three parameters: an array of integers the logical size of the array an element we're interested in finding in the array (we call this the search key ) The function should go through the array one element at a time, checking each element to see if it's the search key. The function should return the index where the search key is located. Keep in mind that the search key may not be found. Devise an elegant way to return this information. Write a main program that tests your function with user interaction. Ask the user to enter a value to look up, call your function to do the search, and report the results back to the user in a user-friendly way. Input of the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: array is not a concern here, so I'll provide you code that hardcodes an array we can use for testing: int testarray[10]; // array to test the search testarray[0] = 12; testarray[1] = 2; testarray[2] = 33; testarray[3] = 0; testarray[4] = 7; testarray[5] = 66; testarray[6] = 7; testarray[7] = 123; testarray[8] = 92; testarray[9] = 89; Sample Interactions Enter an integer value to look up: 2 2 was found at index 1 Enter an integer value to look up: 3 3 was not found. Enter an integer value to look up: 89 89 was found at index 9 Enter an integer value to look up: 66 66 was found at index 5 Lab Report Code -- function and a main program to test it Sample runs - at least 4...
View Full Document

Page1 / 2

lab18 - array is not a concern here, so I'll provide you...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online