fixed和setprecision的使用
原来我只会printf输出题目一次定下的位数,现在题目要求的小数位数会改变,所有就学习了一下C++的输出格式
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, x;
cin >> n >> x;
double ans = sqrt(n+1.0) - 1;
//头文件是#include <iomanip>
// fixed 表示位数不够补零
// setpercision(x) 表示保留x位小数
cout << fixed << setprecision(x) << ans << endl;
return 0;
}