gpt4 book ai didi

c - 为什么包含 tab 时 printf 数字的结果会改变?

转载 作者:行者123 更新时间:2023-11-30 20:49:57 25 4
gpt4 key购买 nike

下面的代码显示 44 和 84 的错误结果。

enter image description here

因此,我尝试将\t 更改为空格,并且数字正确显示,如下所示。

enter image description here

为什么 printf 中只包含制表符会导致数字打印不正确?我尝试将4改为7和8,也出现了同样的问题。

#include <stdio.h>

int main()
{
for (int count = 1; count <= 100 ; ++count)
{
if((count % 4) == 0 )
printf("%d\t", count);
}

return 0;
}


#include <stdio.h>

int main()
{
for (int count = 1; count <= 100 ; ++count)
{
if((count % 4) == 0 )
printf("%d ", count);
}

return 0;
}


最佳答案

它打印正确,但由于在线编译器切断了第一个数字(由于某种原因),您无法看到它。如果您单击输出屏幕上方的第三个按钮(这将复制输出)并将其粘贴到记事本中,您将看到您的输出是正确的。

关于c - 为什么包含 tab 时 printf 数字的结果会改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55718881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com