怎么在C++中算出小数
求助如何在C++中算出小数
想做个函数,希望能得出1除2,1除4,1除8。。。。的结果,可是我不知道如何求出带小数的例如1.5, 2.345。。。希望高人赐教
------解决方案--------------------
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float bn;
for (bn = 5; bn < 25; bn += 2)
{
cout < < setprecision(5) < < (1 / bn) < < endl;
}
return 0;
}
想做个函数,希望能得出1除2,1除4,1除8。。。。的结果,可是我不知道如何求出带小数的例如1.5, 2.345。。。希望高人赐教
------解决方案--------------------
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float bn;
for (bn = 5; bn < 25; bn += 2)
{
cout < < setprecision(5) < < (1 / bn) < < endl;
}
return 0;
}