这道题有两种办法。一种是用 cout 保留小数,另外一种则是用 printf 保留小数。
用 cout :
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a, b;//因为后面要除,所以要设为浮点数形式。
cin >> a >> b;
cout << fixed << setprecision(9) << a / b;
return 0;
}用 printf :
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double a, b;//因为后面要除,所以要设为浮点数形式。
scanf("%lf%lf", &a, &b);
printf("%.9lf", a / b);
return 0;
}