1 条题解
-
0
练7.2 保留12位小数
解题思路
用双精度读入数,固定小数格式输出 12 位。
正确性说明
fixed 与 setprecision(12) 指定所要求的小数位数,由输出流处理舍入。
易错点
不要手动截断;不能把有效数字误认为小数位数。
复杂度
本题规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); double x; cin >> x; cout << fixed << setprecision(12) << x << "\n"; return 0; }
- 1