#include "stdafx.h"
#include "stdio.h"
#include "math.h"
int main()
{
float c;
printf("Type c");
scanf("%f", &c);
printf("C is c: %f ",c);
while(getchar()!='\n');
getchar();
return 0;
}
非常简单的代码,我刚开始与C 对于大多数数字工作正常,但是,例如,如果我输入47.2然后打印我47.200001与88.4321输出88.432098 但与其他号码,如5.4工程确定5.400000 我使用Microsoft Visual Studio 10.scanf浮点数,打印浮点数,不同的值?
另一件事,如果上面的代码,而不是把float c我把双我不能够printf我应该把什么,而不是%f? 但它更担心我的第一个问题,也许这是与编译器有关,也许我正在编译C代码作为C++,我不知道。
%lf将打印双打 – 2011-12-14 21:28:02
`%lf`和`double` ftw – Nakilon 2012-11-28 12:37:26