Array Exercises
1. Create a sketch that declares an array of integers with 10 elements and initialize with the user input (ask function). Only allow the user to input positive numbers. Use a for loop to process the array.
Using the populated array
2. Write a sketch that declares an integer array of 20 elements and populate each element with a random number between 1 and 50. Once the array is populated, allow the user to enter and number and search the array for that number. Tell the user whether or not the number is in the array and if it is, the index number of that number.
Sample output:
45 is not in the array
23 is at index 13 of the array
15 marks
Using the populated array
- Display all the elements of the array.
- Calculate the sum of the values and displays the result to the console.
- Calculate the average of the values and displays the result to the console.
- Determine the maximum value and display it to the console.
- Determine the minimum value and display it to the console.
2. Write a sketch that declares an integer array of 20 elements and populate each element with a random number between 1 and 50. Once the array is populated, allow the user to enter and number and search the array for that number. Tell the user whether or not the number is in the array and if it is, the index number of that number.
Sample output:
45 is not in the array
23 is at index 13 of the array
15 marks