- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图阻止在每行输出的末尾打印尾随选项卡。我怎样才能做到这一点?
其余代码可以按照我的需要工作
#include <stdio.h>
int main()
{
int i, j, k, y, z, x, c, b, a, C;
scanf("%d", &x);
for(i=0; i<x; i++){
for(j=0; j<x; j++){
int c = 0;
for(k=0; k<x; k++){
y = (i+1)*(k+1);
z = (j+k);
c = (z*y)+c;
}
printf("%d\t", c);
}
printf("\n");
}
}
最佳答案
\t
和\n
分别是制表符和换行符转义序列,因此更改
printf("%d\t", c);
到
printf("%d", c);
摆脱标签,并删除
printf("\n");
一起,松开新的线条......很容易
顺便说一句:你为什么要声明第二个int c
?您的代码首先声明一堆整数,其中一些您不使用:
int i, j, k, y, z, x, c, b, a, C;
//last 3 aren't used
//c declared here, though
//I'd write:
int i, j, k, y, z, x, c;
再往下:
//inside second loop:
int c = 0;
//would be better if wou wrote:
c = 0;
最后的注释:您缺少 return
声明,但是你的main
函数的签名表明(正确地)主函数应该返回 int,而不是 void。
添加return 0;
在最后
如果您唯一想避免打印的是最后\n(和\t),您可以更改:
printf("\n");
与
if (i < x-1) printf("\n");
每次都会打印\n,除了循环运行的最后时间。很简单,因为循环运行的条件是 i<x
,打印换行符的条件是i<x-1
.
就您的选项卡而言,替换:
printf("%d\t", c);
与:
if (j < x - 1) printf("%d\t", c);
else printf("%d", c);
正是您所需要的。
也就是说,从x
开始是一个常量值,最好分配 x-1
到那些未使用但已声明的整数之一:
scanf("%d", &x);
a = x -1;
然后,由于您正在使用以下代码检查何时打印一行的最后一个数字:
if (j < a) printf("%d\t", c);//replaced x - 1 with a here
else printf("%d", c);
您可以放心地假设else
子句仅适用于每行的最后一个数字,那么为什么不在那里添加换行符呢?
if (j < a) printf("%d\t", c);//replaced x - 1 with a here
else printf("%d\n", c);
总的来说,这将为您留下以下代码:
#include <stdio.h>
int main()
{
int i, j, k, y, z, x, c, a;
scanf("%d", &x);
a = x - 1;
i = 0;
for(i=0; i<x; i++){
for(j=0; j<x; j++){
c = 0;
for(k=0; k<x; k++){
y = (i+1)*(k+1);
z = (j+k);
c = (z*y)+c;
}
if (j < a) printf("%d\t", c);
else printf("%d\n", c);
}
}
return 0;//ADD A RETURN STATEMENT!!
}
这仍然在最后一行输出之后添加一个新行。要删除它,也只需编写:
if (j < a) printf("%d\t", c);
else if (i < a) printf("%d\n", c);//check if we're in the last i-loop
else printf("%d", c);//if so, don't print new line
工作完成...我已经尝试过此代码 and you can see the output on this codepad
关于c - 删除c程序中的制表符/空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19978601/
使用制表符 - 最初,当我构建表时,我可以在列定义中提供验证选项: {title:"Rating", field:"rating", editor:"input", validator:"requir
在 Notepad++ 中有一个非常方便的按钮,我可以按下它来查看空格、制表符和换行符所在的符号,这样我就可以看到哪些空格是由空格引起的,哪些是由制表符引起的。我可以在 emacs 中做到这一点吗?如
我在 .NET Windows 窗体应用程序中使用 RichTextBox 控件。我允许用户在文本框本身内按 TAB 键。但是,当我将 .Text 值保存在文本框中时,它将显示如下: "This[]i
我想知道如何使用 Interactive Demo 上使用的选择器来清除过滤器对于性别标题。 最佳答案 如果您询问如何向选择 header 过滤器添加空选项,则只需在 headerFilterPara
我有一个包含搜索结果的制表器。这是代码: var table = new Tabulator("#json-table", { layout:"fitDataFill", //init
我正在尝试构建一个可由用户修改的交互式表格。就我而言,原始数据集是本地对象数组。 制表符具有用于删除行的buttonCross选项,但它仅影响表格视觉效果。如何让它找到该行呈现的匹配对象并将其从表数据
我正在制作许多原始 html 表格并使用它们将它们转换为制表符 var table = new Tabulator("#main", { layout:"fitColumns", to
这个问题在这里已经有了答案: Any way for a combo box with 2 values per line? (3 个答案) 关闭 9 年前。 我有一个包含各种项目的 CSV 文件。
我是 JavaScript 的新手,目前正在学习如何使用 Tabulator(除此问题外它工作得很好)。 我想为每个列标题添加一个菜单按钮,然后打开一个下拉菜单。从此菜单中,用户应该能够选择“Grou
我正在尝试处理文本区域中的粘贴代码,并希望对粘贴到第一个非间距字符的内容进行左 trim 。我想采用以下代码: if (foo) { console.log(bar);
我预计 TAB 字符会比 SPACE 字符宽,但在 HTML5 canvas 中,它们是相同的。加上其他一些,这不是那么重要: var c=document.getElementById('mycan
在 shell(GNU bash,版本 4.2.47(1)-release (x86_64-suse-linux-gnu))中,当我点击自动完成选项卡时,“$”在之后被转义变量名称已完成,但如果没有完
我正在制作一个程序,我将从 mysql 表中的 txt 文件加载数据。我将创建具有特定字段的表,然后我将从其中的 txt 文件加载数据。我正在使用 java 来执行该程序。 我写的是下面的内容: pr
Tabulator 有一个名为Column Calculations 的模块。 我需要添加页面总和和总和 例如,我可以添加页脚来计算总和,但我无法添加可见行总和,或者换句话说当前页面的总和仅在同一时间
我不是 javascript 专家,所以我有一个简短的问题,有人知道如何在这里使用 JavaScript tabifier - http://www.barelyfitz.com/projects/t
这是我之前问题的延续(如果你好奇,请检查它们)。 我已经看到了隧道尽头的曙光,但还有最后一个问题。 出于某种原因,每一行都以制表符开头。 我怎样才能忽略第一个字符(在我的例子中是“制表符”(\t))?
请指教以下理解问题??? 我在我的 Linux 机器上输入:(以便通过 top 命令获取总内存) top -n1 | grep Mem: Mem: 2075024k total, 2059064
我该如何解决这个问题: 原因: java.lang.IllegalArgumentException: String [\t] with length 2 cannot be co
1.用法 \t 表示制表符,相当于制表符 前面的输出内容位数为8的倍数,\t将输出8个空格 前面的输出内容位数不是8的倍数,\t将补足8位 2.测试用例 少于8位 等于8位 大于8位
我正在尝试将 Tabulator v4.6.3 与 fitData 布局一起使用。这是我的代码: var table = new Tabulator("#cowTable", { da
我是一名优秀的程序员,十分优秀!