Make the necessary changes to the program to sum the elements of an array of flo
ID: 3641267 • 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 arrayfloat 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; ptrRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.