You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//错误的代码,原因:double存在精度的问题
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
double s = 0;
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (double i = 0.1; i != n; i += 0.1) {
|
|
|
|
|
s += i;
|
|
|
|
|
cout << i << endl;
|
|
|
|
|
}
|
|
|
|
|
cout << s;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|