Question
Design and implement three functions that process the array intArray created in the sample program, including showDataFromArray( ), findMax( ), and average( ). Sample calls
Design and implement three functions that process the array intArray created in the sample program, including showDataFromArray( ), findMax( ), and average( ). Sample calls to those functions are shown as comments in the sample program.
The function showDataFromArray( ) takes the intArray and the number of elements as parameters, and shows each of the elements currently in the array (along with its respective index value in that array).
The function findMax( ) searches through the intArray to find the largest number currently in that array.
The function average( ) calculates and returns the average of all numbers currently in that array.
Implement the showDataFromArray( ) and the findMax( ) functions. When ready, uncomment the respective sample calls in the main( ) function, and then run the revised program.
What I have so far
#define _CRT_SECURE_NO_WARNINGS
#include
#define SIZE 100
void initializeArray(int[SIZE]); //initialize each element to be zero
int getDataIntoArray(int[SIZE]); //This function takes as a parameter an array of strings.
void showDataFromArray(int[SIZE], int); //show all the elements in a given array
void findMax(int[SIZE], int); //find the largest number in the given array
double average(int[SIZE], int); //return the average of all numbers in the given array
void main() {
int intArray[SIZE];
initializeArray(intArray);
int number = getDataIntoArray(intArray);
printf("number: %d ", number);
/* Uncomment the following statements when new functions have been coded.
printf(" Calling the showDataFromArray() function ... ");
showDataFromArray(intArray, number); //Display all the names currently in that array.
printf(" Calling the findMax() function ... ");
findMax(intArray, number);
printf(" Calling the average() function ... ");
printf("The average of all entered numbers is %.2f. ", average(intArray, number));
*/
}
void initializeArray(int arr[SIZE]) {
for (int i = 0; i < SIZE; i++)
arr[i] = 0;
}
int getDataIntoArray(int arr[SIZE]) {
int num = 0;
int index = 0;
do {
printf("Please enter a number between 0 and 100 (or -1 to quit): ");
scanf("%d", &num);
printf("X: %d ", num);
if (num != -1) {
printf("copying data into array ... ");
arr[index] = num;
index++;
}
} while (index < SIZE && num != -1);
if (index > 0)
printf(" You have successfully entered %d items. ", index);
else
printf("No item was entered. ");
return index;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started