Created
October 5, 2017 03:19
-
-
Save YulongNiu/6a0917ba4543d8a76da472219bb3aea6 to your computer and use it in GitHub Desktop.
Sum from 0.01 to 1 by using double
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> | |
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