鱼C论坛

 找回密码
 立即注册
查看: 1517|回复: 2

[已解决]学C第一季第4课,作业问题求助

[复制链接]
发表于 2021-10-4 00:28:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
QQ截图20211004002517.png QQ截图20211004002527.png QQ截图20211004002542.png
为啥那个指数输出和答案上的始终不一样,我+后面总是有2个零,题目只有1个,而且我复制答案代码再运行也是那个样子
最佳答案
2021-10-4 10:03:14
这是微软的问题
http://cn.voidcc.com/question/p-xqgtlycy-kb.html
https://docs.microsoft.com/en-us ... N&view=msvc-160
The %e and %E format specifiers format a floating point number as a decimal mantissa and exponent. The %g and %G format specifiers also format numbers in this form in some cases. In previous versions, the CRT would always generate strings with three-digit exponents. For example, printf("%e\n", 1.0) would print 1.000000e+000, which was incorrect. C requires that if the exponent is representable using only one or two digits, then only two digits are to be printed.

In Visual Studio 2005 a global conformance switch was added: _set_output_format. A program could call this function with the argument _TWO_DIGIT_EXPONENT, to enable conforming exponent printing. The default behavior has been changed to the standards-conforming exponent printing mode.

下面是有道翻译
%e和%e格式说明符将浮点数格式化为十进制尾数和指数。在某些情况下,%g和%g格式说明符也会格式化这种形式的数字。在以前的版本中,CRT总是生成具有三位指数的字符串。例如,printf("%e\n", 1.0)将输出1.000000e+000,这是不正确的。C要求如果指数只能用一个或两个数字表示,那么只能打印两个数字。


在Visual Studio 2005中添加了一个全局一致性开关:_set_output_format。程序可以使用参数_TWO_DIGIT_EXPONENT调用此函数,以启用符合标准的指数打印。默认行为已更改为符合标准的指数打印模式。
#include <stdio.h>

int main(void) {
    printf("%E\n", 5200000.0);
    _set_output_format(_TWO_DIGIT_EXPONENT);
    printf("%E\n", 5200000.0);
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-4 07:14:26 From FishC Mobile | 显示全部楼层
这无所谓啊05和005不都是一个东西吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-4 10:03:14 | 显示全部楼层    本楼为最佳答案   
这是微软的问题
http://cn.voidcc.com/question/p-xqgtlycy-kb.html
https://docs.microsoft.com/en-us ... N&view=msvc-160
The %e and %E format specifiers format a floating point number as a decimal mantissa and exponent. The %g and %G format specifiers also format numbers in this form in some cases. In previous versions, the CRT would always generate strings with three-digit exponents. For example, printf("%e\n", 1.0) would print 1.000000e+000, which was incorrect. C requires that if the exponent is representable using only one or two digits, then only two digits are to be printed.

In Visual Studio 2005 a global conformance switch was added: _set_output_format. A program could call this function with the argument _TWO_DIGIT_EXPONENT, to enable conforming exponent printing. The default behavior has been changed to the standards-conforming exponent printing mode.

下面是有道翻译
%e和%e格式说明符将浮点数格式化为十进制尾数和指数。在某些情况下,%g和%g格式说明符也会格式化这种形式的数字。在以前的版本中,CRT总是生成具有三位指数的字符串。例如,printf("%e\n", 1.0)将输出1.000000e+000,这是不正确的。C要求如果指数只能用一个或两个数字表示,那么只能打印两个数字。


在Visual Studio 2005中添加了一个全局一致性开关:_set_output_format。程序可以使用参数_TWO_DIGIT_EXPONENT调用此函数,以启用符合标准的指数打印。默认行为已更改为符合标准的指数打印模式。
#include <stdio.h>

int main(void) {
    printf("%E\n", 5200000.0);
    _set_output_format(_TWO_DIGIT_EXPONENT);
    printf("%E\n", 5200000.0);
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-22 12:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表