Skip to content

Instantly share code, notes, and snippets.

@tkhduracell
Last active September 24, 2017 10:40
Show Gist options
  • Save tkhduracell/90a970e47f7c3c01e0195a1b79f3625b to your computer and use it in GitHub Desktop.
Save tkhduracell/90a970e47f7c3c01e0195a1b79f3625b to your computer and use it in GitHub Desktop.
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