# Answer to Question #44350 in C for erico fire

Question #44350

write a Program in c to find the sum and average of 1D array?

Expert's answer

int calculateSum(int *arr, int size)

{

int sum = 0;

for(int i = 0; i < size; ++i)

sum += arr[i];

return sum;

}

int main()

{

const int size = 5;

int arr[size] = {1, 2, 3, 4, 5};

int sum = calculateSum(arr, size);

printf("sum: %i\navg: %f\n", sum, (float)sum / size);

return 0;

}

{

int sum = 0;

for(int i = 0; i < size; ++i)

sum += arr[i];

return sum;

}

int main()

{

const int size = 5;

int arr[size] = {1, 2, 3, 4, 5};

int sum = calculateSum(arr, size);

printf("sum: %i\navg: %f\n", sum, (float)sum / size);

return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment