Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make the necessary changes to the program to sum the elements of an array of flo

ID: 3641280 • Letter: M

Question

Make the necessary changes to the program to sum the elements of an array of floats instead of an array of ints. Use the array
float values[10] = {-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0};

// Function to sum the elements of an integer array

#include <stdio.h>

int arraySum (int array[], const int n)
{
int sum = 0, *ptr;
int * const arrayEnd = array + n;


for ( ptr = array; ptr < arrayEnd; ++ptr )
sum += *ptr;
return sum;
}

int main (void)
{
int arraySum (int array[], const int n);
int values[10] = {3, 7, -9, 3, 6, -1, 7, 9, 1, -5};

printf("The sum is %i ", arraySum (values, 10));

return 0;

}

Explanation / Answer

Hi I modified the code and ran it . It works perfectly . Hope it helps you . #include float arraySum (float array[], const int n) { float sum = 0, *ptr; float * const arrayEnd = array + n; for ( ptr = array; ptr
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote