Advertisement
M_c_Ruer

Untitled

Feb 28th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. CS 1050 Prelab 5 – Arrays – SPRING 2012
  2.  
  3. Directions:
  4. Use the following prelab assignment to aid in your preparations for Lab 5.
  5.  
  6. Purpose:
  7.  
  8. Use an array to store data
  9. Use loops to access and modify an array
  10. Use functions with an array
  11.  
  12. Description:
  13.  
  14. You will have to write a program that will gather input from the user and store it into an array. Your program will then search the array for a value and return whether it is found or not. The array should have a constant size by using a #define statement at the top of your program, like so:
  15.  
  16. #define MAX_SIZE 5
  17.  
  18. Your program should ask for numbers from the user and store them in the array. (Assume they will all be integers.) Afterwards, you should display a prompt asking the user what they want to search for. See the example output for details.
  19.  
  20. Program variables and function prototypes
  21.  
  22. Define a constant in the program MAX_SIZE and make it equal to 100. Here are the functions you will need to implement for this prelab. size is the number of items stored in the array and not MAX_SIZE :
  23.  
  24. int find(int array[], int size, int target);
  25. - Searches the array for target. Returns the index if found, otherwise -1.
  26.  
  27. Example output (bold is user input):
  28.  
  29. $ ./a.out
  30. How many scores do you want to enter? 3
  31. Enter score 1: 1
  32. Enter score 2: 2
  33. Enter score 3: 3
  34. Score to look for: 3
  35. Score found at: 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement