Scanf for double在Dev C ++中不起作用 [英] Scanf for double not working in Dev C++
问题描述
我对浮点数有疑问。我认为这里发生了冲突。
I am having problem with floating point numbers. I think something is clashing here.
输出为:
我的代码:
#include <stdio.h>
int main(){
double y;
printf("enter a decimal number: ");
scanf("%f", &y);
printf("%f\n", y);
fflush(stdin);
getchar();
return 0;
}
我正在使用Dev C ++ 4.9.9.2,首先使用,如果以前没有阅读过,我必须冲洗回车几次。因此,如果有其他选择,请告诉我。其次,输出给出了...
I am using Dev C++ 4.9.9.2 and first of all, I have to flush the carriage return out several times if it's not read previously . So if there is any alternative there then tell me. And secondly the output is giving this...
推荐答案
使用
scanf("%lf", &y);
。由于 scanf(%f,& y);
仅适用于 float
s。
instead. Since scanf("%f", &y);
works for float
s only.
如果启用编译器警告,它将告诉您格式说明符%f
期望 float *
而不是 double *
参数。
If you enable compiler warnings it would tell you that the format specifier "%f"
expects a float *
and not double *
argument.
这篇关于Scanf for double在Dev C ++中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!