阅读科学记数法 scanf [英] Read scientific notation scanf

查看:66
本文介绍了阅读科学记数法 scanf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个程序,它应该只有一个 scanf 函数,它应该能够接受科学计数法和实数的输入.

I am developing a program which should have only one scanf function and it should be able to accept input in scientific notation and real numbers.

任何帮助将不胜感激

推荐答案

根据scanf 文档:

%f 匹配一个浮点数.数字的格式与strtof()所期望的一样.

%f matches a floating-point number. The format of the number is the same as expected by strtof().

查看 strtof 文档

(可选)eE 后跟可选的减号或加号和非空十进制数字序列(定义指数)

(optional) e or E followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent)

因此,您可以使用 %f 说明符读取 e 符号中的数字.那是,1e-31 * 10 ^ -3.

Thus, you can use the %f specifier to read numbers in e notation. That is, 1e-3 is 1 * 10 ^ -3.

这篇关于阅读科学记数法 scanf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆