失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > c语言scanf输入无理数 简单C语言scanf输入问题

c语言scanf输入无理数 简单C语言scanf输入问题

时间:2022-10-01 00:29:19

相关推荐

c语言scanf输入无理数 简单C语言scanf输入问题

匿名用户

1级

-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里是没有协处理器的。

如果觉得《c语言scanf输入无理数 简单C语言scanf输入问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。