Question: 1- Write a program that creates an array of 20 integers. Fill the array with random numbers from 10 through 100. Seed the random number
1- Write a program that creates an array of 20 integers. Fill the array with random numbers from 10 through 100. Seed the random number generator with the systems clock so that it generates a different sequence of numbers each time you run the program.
Write a function for each of the following operations (write the functions in the order given below and test each one before writing the next):
- Output the contents of the array, 5 elements on each line
void print (int [] array , int size , int perLine)
- Return the index of the smallest value in the array. If the smallest value is not unique, then return the index of the first occurrence of the smallest element
int indexOfSmallest (int [] array , int size)
- Print out a slice of the array (a segment of the array) starting at position p and of size s, where the values for p and s are read from the keyboard. If you reach the end of the array before printing s values, wrap around and start at the beginning of the array and continue. It can be assumed that s is no bigger than the array size, and p is a valid array position. This function does not read any data from the keyboard, the values for p and s are read in the main and passed as arguments to this function.
void slice (int [] array , int size , int p , int s)
Include a loop in the program to allow the user to repeat the above process as many times as she/he wishes.
Sample Input and Output: Since the numbers are generated randomly, your result may differ from the output below. Verify the correctness of your output before handing it in.
Programmer: Name of the programmer (your name)
Course: COSC246, Winter 2016
Lab#: 9
Due Date: 3-31-16
The array contains:
92 71 20 13 18
65 21 72 97 81
73 22 87 19 99
100 64 29 45 88
The index of the smallest element is: 3
Enter the starting position of the slice: 17
Enter the size of the slice: 5
29 45 88 92 71
Do it again, yes (or no)? YES
The array contains:
18 11 20 23 68
75 29 72 98 51
73 28 17 39 79
90 68 19 35 85
The index of the smallest element is: 1
Enter the starting position of the slice: 3
Enter the size of the slice: 2
23 68
Do it again, yes (or no)? no
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
