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

C programming language Programming 2 Spring 2011 4. Write a function that receiv

ID: 3743062 • Letter: C

Question

C programming language

Programming 2 Spring 2011 4. Write a function that receives two parameters: the pointer to the first element of an arr av integers, and the number of elements in that arrav, and returns number of elements greater than mean value of elements in that array. If number of elements in the array is less than function should return o Example: 10 10 10 10 1 The mean value of the string elements is 82. The function should return number 4 because 4 elements are greater than the averace Example: Array: 10 Returns: 0 NOTE: Also, write the main function together with the variables declarations a function.

Explanation / Answer

#include <stdio.h>

==========================================================

// BELOW IS THE FUNCTION REQUIRED IN QUESTION:

int function(int *p, int n)

{

int sum=0, mean=0, ans=0;

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

{

// printf("x: %d ", *(p+i));

sum+=*(p+i);

}

// printf("%d", sum);

mean = sum/n;

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

{

// printf("x: %d ", *(p+i));

if(*(p+i)>mean)

ans++;

}

return ans;

}

=================================================================

int main(void) {

int arr[] = {10,10,10,10,1};

int *p;

p=arr;

int output = function(p, 5);

printf("%d", output);

return 0;

}