Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the following function in skeleton code lab 1 part 2 . c: / / Let n be the minimum of n 1 and n

Implement the following function in skeleton code lab1part2.c:
// 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
//Calculate the sum of the array elements for each array
//Print difference between the total sums and comparison of them
//If total sums are equal print out The total sums are equal.
//If the total sum of the first array is less than the second array, print out The total sum of the first
array is less than the second array
//If the total sum of the first array is greater than the second array, print out The total sum of the
first array is greater than the second array
int compareTwoArrays(const int arr1[], const int arr2[], int n1, int n2);
int calculateSum(const int arr[], int n);
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
Total sum of the first array: 15
Total sum of the second array: 15
Difference between the total sums: 0
The total sums are equal.
Computer Engineering Department
TED University
Sample Run 2:
Enter the number of elements:
5
Enter 5 elements:
12345
Array elements: 12345
Enter the number of elements:
5
Enter 5 elements:
14789
Array elements: 14789
Less than
Total sum of the first array: 15
Total sum of the second array: 29
Difference between the total sums: -14
The total sum of the first array is less than the second array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions