Created
December 16, 2025 22:45
-
-
Save ShrootBuck/cd014ffa813c0c6c373afe04b22f668f to your computer and use it in GitHub Desktop.
a fast standard deviation + mean calculator for my physics labs
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
| #include <algorithm> | |
| #include <cmath> | |
| #include <cstdio> | |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| using namespace std; | |
| void setIO(string name = "") { | |
| ios_base::sync_with_stdio(false); | |
| cin.tie(NULL); | |
| if (!name.empty()) { | |
| freopen((name + ".in").c_str(), "r", stdin); | |
| freopen((name + ".out").c_str(), "w", stdout); | |
| } | |
| } | |
| int main() { | |
| setIO("f"); | |
| vector<double> values; | |
| double val; | |
| while (cin >> val) { | |
| values.push_back(val); | |
| } | |
| if (values.empty()) | |
| return 0; | |
| double sum = 0; | |
| for (double x : values) { | |
| sum += x; | |
| } | |
| double mean = sum / values.size(); | |
| double sq_sum = 0; | |
| for (double x : values) { | |
| sq_sum += (x - mean) * (x - mean); | |
| } | |
| double std_dev = sqrt(sq_sum / values.size()); | |
| cout << "Average: " << mean << "\n"; | |
| cout << "Standard Deviation: " << std_dev << "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment