Last active
September 24, 2017 10:40
-
-
Save tkhduracell/90a970e47f7c3c01e0195a1b79f3625b to your computer and use it in GitHub Desktop.
This file contains 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
static void main(char*[] args) { | |
int[] numbers = {11,12,13, 21,22,23, 31,32,33}; | |
int intervalMin = 10; | |
int intervalMax = 20; | |
cout << "10-20: Average is " << getAverage(numbers, 10, 20) << endl; | |
} | |
static float getAverage(int[] numbers, int intervalMin, int intervalMin) { | |
long sumOfNumbersInInterval = 0; | |
long countOfNumbersInInterval = 0; | |
for (int i = 0; i < numbers.length; i++) { | |
if (numbers[i] > intervalMin && numbers[i] < intervalMax) { | |
sumOfNumbersInInterval += numbers[i]; | |
countOfNumbersInInterval += 1; | |
} | |
} | |
return sumOfNumbersInInterval / countOfNumbersInInterval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment