Skip to content

Instantly share code, notes, and snippets.

@thearyanag
Created September 9, 2022 13:06
Show Gist options
  • Select an option

  • Save thearyanag/136815ddb4e7d0fdf960b80b20fdd6a3 to your computer and use it in GitHub Desktop.

Select an option

Save thearyanag/136815ddb4e7d0fdf960b80b20fdd6a3 to your computer and use it in GitHub Desktop.
Find the counts of elements of an unsorted integer array which are equal to the average of all elements of that array.
// Find the counts of elements of an unsorted integer array which are equal to the average of all elements of that array.
int count(int arr[])
{
int count=0,avg=0;
int l = arr.length;
for(int i=0 ; i<l ; i++)
{
avg = avg + arr[i];
}
avg = avg / l;
for(int i=0 ; i<l ; i++)
{
if(arr[i] == avg)
{
count++;
}
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment