Created
September 9, 2022 13:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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