gpt4 book ai didi

c - 输出正确对齐

转载 作者:行者123 更新时间:2023-11-30 15:28:46 24 4
gpt4 key购买 nike

我写了一段代码,它给了我我想要的确切输出,除了一件事,输出中整数的对齐是从左到右,但我需要它从从右到左。

这是我的代码:

#include <stdio.h>

int main()
{

int cols, rows, i,j,num;

scanf("%d %d",&rows, &cols);


for (i=1; i<=1; i++){

for (j=0; j<=cols; j++){

if (j==0) printf("\t ");

else {

num=j;

printf("\t%d", num);

}

}

printf("\n");

}


for (i=2; i<=rows; i++){

for (j=0; j<=cols; j++){

if (j==0) num=i;

else num=power(i,j);


printf("\t%d", num);

}

printf("\n");

}



return 0;
}
<小时/>

我得到的输出是

My output

<小时/>

所需的输出是

Required Output

最佳答案

使用例如%6dprintf() 格式说明符中,并且不要使用制表符。

参见the manual对于格式说明符语法。字段宽度是标准功能。

关于c - 输出正确对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26466530/

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