Skip to content

Instantly share code, notes, and snippets.

@YulongNiu
Created October 5, 2017 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YulongNiu/6a0917ba4543d8a76da472219bb3aea6 to your computer and use it in GitHub Desktop.
Save YulongNiu/6a0917ba4543d8a76da472219bb3aea6 to your computer and use it in GitHub Desktop.
Sum from 0.01 to 1 by using double
#include <iostream>
int main() {
double sum = 0.0;
double step = 0.01;
double each = 0.01;
for (int i = 0; i < 100; ++i) {
sum += step;
step += each;
}
std::cout << sum << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment