69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int main() {
float f=1.234567f;
double lf=1.234567890123456;
printf("%f ,%.15lf\n",f,lf);//1.234567 ,1.234567890123456
printf("%f ,%.15f \n",f,lf);//1.234567 ,1.234567890123456
printf("%lf,%.15lf\n",f,lf);//1.234567,1.234567890123456
char s[]="1.234567890123456";
f =0.0f;sscanf(s,"%f" ,& f); printf("%f \n", f);//1.234568
lf=0.0 ;sscanf(s,"%lf",&lf); printf("%.15lf\n",lf);//1.234567890123456
lf=0.0f;sscanf(s,"%f" ,&lf); printf("%.15lf\n",lf);//0.000000000000000
f =0.0 ;sscanf(s,"%lf",& f); printf("%f \n", f);//70.175720
return 0;
}
//根据以上运行结果可得:printf时,%lf和%f可以混用,scanf时不行。