Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

! ! ! PLEASE SOLVE USING C LANGUAGE!! Part 2 ( 3 5 points ) Implement the following function in skeleton code 1 ab 1

!!!PLEASE SOLVE USING C LANGUAGE!! Part 2(35 points)
Implement the following function in skeleton code 1ab1part2. c:
Your task in this part to fill in the missing function definitions in skeleton code lab1part2. c.
main function will stay as it is.
Sample Run:
Enter the number of elements:
5
Enter 5 elements:
12345
Array elements: 12345
Enter the number of elements:
5
Enter 5 elements:
12345
Array elements: 12345
Equal
Average of the first array: 3
Average of the second array: 3!!!!HERE IS THE CODE STRUCTURE/SKELETON CODE lab1part2.c. : #include
#define SIZE 500
// reads numbers from the standard input into arr,
// and stores the number of read elements in the memory cell pointed to by nPtr
void readInput(int arr[], int *nPtr);
// prints the elements in arr[0..(n-1)]
void printNumbers(const int arr[], int n);
// Let n be the minimum of n1 and n2 where n1 and n2 are the number of elements in
// arr1 and arr2, respectively.
// Compare corresponding elements of arr1 and arr2 at each of the first n positions.
//
// If arr1 and arr2 has the same value in each position:
// Return 0 if n1== n2
// Return 1 if n1> n2
// Return -1 if n1 n2
//
// If arr1 has a larger value than arr2 considering the first position from the
// beginning at which arr1 and arr2 have a different value:
// Return 1
//
// If arr1 has a smaller value than arr2 considering the first position from the
// beginning at which arr1 and arr2 have a different value:
// Return -1
int compareTwoArrays(const int arr1[], const int arr2[], int n1, int n2);
int calculateAverage(const int arr[], int n);
int main()
{
int arr1[SIZE];
int n1;
int arr2[SIZE];
int n2;
readInput(arr1, &n1);
printNumbers(arr1, n1);
readInput(arr2, &n2);
printNumbers(arr2, n2);
int result = compareTwoArrays(arr1, arr2, n1, n2);
if (result ==0)
printf("
Equal
");
else if (result ==-1)
printf("
Less than
");
else if (result ==1)
printf("
Greater than
");
int avg1= calculateAverage(arr1, n1);
int avg2= calculateAverage(arr2, n2);
printf("
Average of the first array: %d
", avg1);
printf("Average of the second array: %d
", avg2);
return 0;
}
void readInput(int arr[], int *nPtr)
{
// fill here
}
void printNumbers(const int arr[], int n)
{
// fill here
}
int compareTwoArrays(const int arr1[], const int arr2[], int n1, int n2)
{
// fill here
}
int calculateAverage(const int arr[], int n)
{
// fill here
}
image text in transcribed

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

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

=+2. Compare and contrast top-down and bottom-up processing.

Answered: 1 week ago