C programming

oeuz

Programming

Question Description

hello,

I have a midterm coming up and I can't figure out one of the practice problems. I think I have the first function done right, but I can't seem to repeat it. Also, I don't know how to use the second function to print out the values.

Please help.

I'm supposed to write a program largeHalf.c that takes in a list of 8 integers, splits the list into two halves (rst 4 elements, last 4 elements), sums the elements in each half, selects the half with the larger sum, and then repeats this process with the selected list until there is only one element selected. The program should print out the half selected at each step. If the two halves have equal sum, the program should tell the user this and should always pick the rst half (the one with a smaller starting index, see the example output below).

must include the following functions:
int sumArray(int array[], int startIdx, int len) - Returns the sum of the elements in array with index startIdx to startIdx+len.

void printArray(int array[], int startIdx, int len) - Print the elements in array with index startIdx to startIdx+len.


Enter 8 numbers: 1 2 3 4 5 4 1 0
The two halves are equal, picking 1 2 3 4
Larger half is 3 4
Larger half is 4
(˜)$ a.out
Enter 8 numbers: 1 4 5 0 -10 10 1 2
Larger half is 1 4 5 0
The two halves are equal, picking 1 4
Larger half is 4

Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

wqjvyyvnzf51 (67)
UT Austin

Anonymous
I was stuck on this subject and a friend recommended Studypool. I'm so glad I checked it out!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4