Problem 147

Where Is It?

Create an array that can hold ten integers, and fill each slot with a different random value from 1-50. Display those values on the screen, and then prompt the user for an integer. Search through the array, and if the item is present, give the index location of the item. If the value is not in the array, display a single message saying so. If the value is present more than once, you may either display the message as many times as necessary, or display a single message giving the last slot number in which it appeared.

Array: 45 39 32 12 44 50 42 26 16 20
Value to find: 42

42 is in slot 6.
Array: 45 39 32 12 44 50 26 42 16 20
Value to find: 43

43 is not in the array.
Array: 24 30 31 24 32 33 34 24 35 36
Value to find: 24

    you may display either

24 is in slot 0.
24 is in slot 3.
24 is in slot 7.

    or

24 is in slot 7.

◄ 146: Is It There or Not? 148: Finding the Largest Value in an Array ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.