Created
July 1, 2021 09:04
-
-
Save chbtoys/9d7da8e2e56c080c8cc1f4fb2a97a67a to your computer and use it in GitHub Desktop.
Code Example. From Paper to Code.
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
// From Paper to Code | |
// Summation | |
// Run with: https://www.jdoodle.com/online-compiler-c++17/ | |
// LaTeX: X = \{X_{1},X_{2},...,X_{n} \}; | |
// LaTeX: avg(X) = \frac{1}{|x|} \sum_{x \epsilon X} x | |
// Test LaTeX: https://quicklatex.com/ | |
#include <iostream> | |
#include <vector> | |
double avg(std::vector<double> &X) | |
{ | |
double temp=0.0; | |
for (auto& x : X) // element x from X (xeX) | |
{ | |
temp = temp + x; | |
} | |
temp = temp*1.0/X.size(); | |
return temp; | |
} | |
int main() | |
{ | |
std::vector<double> grades = {3.0, 1.0, 4.0}; | |
std::cout << "avg(grades) = " << avg(grades) << std::endl; | |
std::cout << "Which is the same as: (3.0+1.0+4.0)/3, which is: " << (3.0+1.0+4.0)/3 << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment