匿名用户
1级
2018-11-19 回答
(1)我初学c语言时也碰到了跟你一样的问题,
那是因为scanf函数的一个天生的毛病,
你在调用scanf()时,输入一个数字,并按下回车,
你的本意是只想让scanf接受一个数字,
但同时scanf()把那个回车也送入了缓冲区中,
你可以这样改:
intx
scanf(“%d”,&x)
或者在scanf下面加一个语句,fflush(stdin);//清空缓冲区的语句
(2)下面有printf语句时,你的回车符就被编译器理解成换行的标识,
这时继续执行下面的语句,就不会出现上述的问题
希望对你有帮助
抱歉,我发现我的解释有误,刚编了一个格式转换的函数,回车也是可以转换成%f的格式的。恕我才疏学浅,我们一起思考一下
以下是我在微软msdn中找到的解释
The program needs the floating-point library, but the library was not linked to the program.
One of the following may have occurred:
The program was compiled or linked with an option (such as /FPi87) that required a coprocessor, but the program was run on a machine that did not have a coprocessor installed. //这是原因之一
A format string for a printf or scanf function contained a floating-point format specification, and the program did not contain any floating-point values or variables. //这是原因之二
The compiler minimizes a program's size by loading floating- point support only when necessary. The compiler cannot detect floating-point format specifications in format strings, so it does not load the necessary floating-point routines. //原因之三
Use a floating-point argument to correspond to the floating-point format specification, or perform a floating-point assignment elsewhere in the program. This causes floating-point support to be loaded. //改正方法
In a mixed-language program, a C library was specified before a FORTRAN library when the program was linked. Relink and specify the C library last.
Also, MSDN Library has the following comment
.
msdn中的错误举例正好就是你的那个程序
英语看的懂吧 呵呵
这个问题已经上升到硬件的程度了,硬件上处理浮点运算还要有一个专门的协处理器,但是我们的cpu里是没有协处理器的。