Code Bye

c++问一下怎样使一个数以一定的精度输出

do{
for(i=1;sum-(int)sum>1.0e-6;i+=2){
sum+=qgcf(x,i);
if(sum-(int)sum>1.0e-6){
cout<<“sum=”<<sum<<endl;
}
}
}while(sum-(int)sum>1.0e-6);
本人写的比较混论
4)
解决方案

10

10

5

printf(“%.5f”,fa);

5

%.15lg

20

#include <stdio.h>
int main() {
    double d;
    int i;
    d=1.23456789012345;
    for (i=1;i<16;i++) {
        printf("%.*lg\n",i,d);
    }
    d=1234567890.12345;
    for (i=1;i<16;i++) {
        printf("%.*lg\n",i,d);
    }
    return 0;
}
//1
//1.2
//1.23
//1.235
//1.2346
//1.23457
//1.234568
//1.2345679
//1.23456789
//1.23456789
//1.2345678901
//1.23456789012
//1.234567890123
//1.2345678901235
//1.23456789012345
//1e+009
//1.2e+009
//1.23e+009
//1.235e+009
//1.2346e+009
//1.23457e+009
//1.234568e+009
//1.2345679e+009
//1.23456789e+009
//1234567890
//1234567890.1
//1234567890.12
//1234567890.123
//1234567890.1235
//1234567890.12345
//

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明c++问一下怎样使一个数以一定的精度输出