Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program #4: The contents of an int array are provided below. You can create and initialize an array with those contents by using an array

Program #4: The contents of an int array are provided below. You can create and initialize an array with those contents by using an array initialization list, as follows: int x[ ] = {120, 80, 72, 143, 123, 124, 125, 3000, 2999, 3000, 82, 876, 986, 345, 1990, 2367, 98, 2, 444, 993, 635, 283, 544, 923, 18, 543, 777, 234, 549, 864, 39, 97, 986, 986, 1, 2999, 473, 776, 9, 23, 397, 15, 822, 1927, 1438, 1937, 1956, 7, 29, -1}; Every element of this array is an int between 0 and 3000, except for the last element, which is -1. Note that you may NOT assume that this is the only array that will be processed by your program. Another set of values may be provided. Since we did not provide a size declarator in the array declaration, nor do we know how many elements are in the array until we process it, that last -1 can be used as a sentinel value for our array processing. It is not considered part of the data set in the array and should not be included in the following calculations. Write a C program that scans through the array contents (everything except the -1) and determines the following statistics on it: 1) the number of elements 2) the average of the elements 3) the minimum and maximum values 4) the second to last minimum and second to last maximum values (if the min or max values are duplicated, use the duplicated value not the next unique value) Your program should analyze the array, determine the above statistics, and print out the results in the following format (example output only). Total number: 700 Average: 2462.9 Min element: 15 Min2 element: 21 Max element: 2984 Max2 element: 2976 The average should be printed as a floating point value with one decimal position. All numbers should be right justified as indicated. Min2 refers to the second-to-smallest minimum element, and Max2 refers to the second-to-largest maximum element. CS1324 page: 2 Note that it is not necessary to create an output file for this project. Printing the results to the console will be sufficient. Note: The easiest way to find the Min2 and Max2 values is to sort the array. The Min, Min2, Max2, and Max elements are then x[0], x[1], x[n-2], and x[n-1] when there are n elements in the array.

Please take both arrays for Program #4 and determine how many duplicate values there are in the array and what their index positions are. The output should look like: Value 1899 was found at indices: 1, 9. Value 1059 was found at indices: 20, 224, 475. Value 1607 was found at indices: 25, 120. Value 2535 was found at indices: 415, 488. Total Duplicates found: XX All of the indices for a given value are listed on one line. Your program should not have more than one entry for the same number. Only numbers that have at least one duplicate should be reported. Notice that commas separate the indices, and the list ends with a period. Note that the meaning of a duplicate is two numbers at different index positions that have the same value. This means that if a number appears n times in the array, there are a total of 2 1 2 duplicates for that number. Thus, if a number appears twice in the array, that contributes 1 duplicate to the total duplicate count. If a number appears 3 times, that contributes 3 duplicates. And if a number appears 4 times, that contributes (4*3)/2 = 6 duplicates to the total duplicate count.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

General Purpose of Your Speech Analyzing Your Audience

Answered: 1 week ago

Question

Ethical Speaking: Taking Responsibility for Your Speech?

Answered: 1 week ago