The language is C Thanks Write a function that computes the
The language is C. Thanks.
Write a function that computes the integer mean of an array of integers. For example, the integer mean of - 1, 4, 2 is (- 1 + 4 + 2)/3 = 5/3 = 1, where/denotes integer division. The function should implement the following specification;/* Computes the integer mean of an array and stores it * where mn references. Returns -J for erroneous input * (lenSolution
// C code
#include <stdio.h>
int mean(int *a, int len, int *mn)
{
if(len <= 0)
return -1;
*mn = 0;
int i = 0;
for (i = 0; i < len; ++i)
{
*mn = *mn + *(a+i);
}
*mn = *mn/len;
return 0;
}
int main()
{
int size;
printf(\"Enter size of array: \");
scanf(\"%d\",&size);
int i;
int array[size];
for (i = 0; i < size; ++i)
{
printf(\"Enter array element at index %d: \",(i+1));
scanf(\"%d\",&array[i]);
}
int mn;
int result = mean(array, size, &mn);
if(result == 0)
printf(\"Mean: %d\ \", mn);
else
printf(\"Erroneous input\ \");
return 0;
}
/*
output:
Enter size of array: 3
Enter array element at index 1: -1
Enter array element at index 2: 4
Enter array element at index 3: 2
Mean: 1
*/

