输出结果数字间怎么有空格

#include
#include
int main()
{
    int i,j,n;
    scanf("%d",&n);
int a[n];
for(i=0;iscanf("%d",&a[i]);
}
for(j=n-1;j>=0;j--)
{
    printf("%d",a[j]);
}
return 0;
}


printf("%d ",a[j]);
在%d后面加个空格

在你的代码中,每次输出一个数字时,你只使用了 printf("%d",a[j]) 这个语句,这样输出的数字是没有空格的。为了在输出数字之间添加空格,可以在 printf 语句中使用空格字符 " "。修改后的代码如下:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i,j,n;
    scanf("%d",&n);
    int a[n];

    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
   for(j=n-1;j>=0;j--)
    {
        printf("%d ",a[j]); // 在 %d 后添加空格
    }

    return 0;
}

这样就可以在输出数字之间添加一个空格了。如果需要在数字之间添加多个空格,可以使用多个空格字符 " ",也可以使用制表符 "\t"。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^