Last active
May 13, 2018 13:35
-
-
Save saschagrunert/67e0194b7cfbfc8c124f11869f60cdbd 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
#include <iostream> | |
#include <vector> | |
auto average(const std::vector<uint32_t> & input) -> double; | |
int main(void) { | |
// Create a vector | |
std::vector<uint32_t> v = {9, 8, 3}; | |
// Get the average | |
const double avg = average(v); | |
// Results in "Average: 6.6667" | |
std::cout << "Average: " << avg; | |
return 0; | |
} | |
double average(const std::vector<uint32_t> & input) { | |
uint32_t sum = 0; | |
for (uint32_t i = 0; i < input.size(); ++i) { | |
sum += input[i]; | |
} | |
return sum / (double)input.size(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment