回答編集履歴
2
std::coutのコードを追記
answer
CHANGED
@@ -3,4 +3,21 @@
|
|
3
3
|
+printf("%.18e\n", a);
|
4
4
|
```
|
5
5
|
|
6
|
-
詳しくは[Man page of printf](https://linuxjm.osdn.jp/html/LDP_man-pages/man3/printf.3.html)の「精度」を参照してください。
|
6
|
+
詳しくは[Man page of printf](https://linuxjm.osdn.jp/html/LDP_man-pages/man3/printf.3.html)の「精度」を参照してください。
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
`std::cout`で書く場合。
|
11
|
+
```C++
|
12
|
+
#include<iostream>
|
13
|
+
#include <iomanip>
|
14
|
+
int main(void)
|
15
|
+
{
|
16
|
+
double a = 1;
|
17
|
+
for (int n = 0; n <= 10; n++) {
|
18
|
+
std::cout << std::fixed << std::scientific << std::setprecision(18) << a << std::endl;
|
19
|
+
a = 1 + 2 / (1 + a);
|
20
|
+
}
|
21
|
+
return 0;
|
22
|
+
}
|
23
|
+
```
|
1
リンク追加
answer
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
```diff
|
2
2
|
-printf("%18e\n", a);
|
3
3
|
+printf("%.18e\n", a);
|
4
|
-
```
|
4
|
+
```
|
5
|
+
|
6
|
+
詳しくは[Man page of printf](https://linuxjm.osdn.jp/html/LDP_man-pages/man3/printf.3.html)の「精度」を参照してください。
|