Last active
December 10, 2018 21:33
-
-
Save aaronang/f6ed29430e91b7495a262052f34a77a5 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
bool double_eq(const double a, const double b) { | |
return std::fabs(a - b) < std::numeric_limits<double>::epsilon(); | |
} | |
double average(const vector<int> &numbers) { | |
int sum = std::accumulate(numbers.begin(), numbers.end(), 0); | |
return sum / numbers.size(); | |
} | |
int main() { | |
vector<int> numbers = {0, 0, 0, 0, 0}; | |
assert(double_eq(average(numbers), 0)); | |
vector<int> numbers = {1, 0, 10, 0, 0}; | |
assert(double_eq(average(numbers), 2.2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment