我运行程序后数字都黏在一起了,想要数字会自动分隔,用的是VS2019

我运行程序后数字都黏在一起了,没有分隔,想要数字会自动分隔,在VS2019中我应该如何操作才能实现想要的效果呢?

目前:
101103107109113127131137139149151157163167173179181191193197199
count = 21
想要效果:
101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199
count = 21

c语言的话,printf("%d "a);空格即可。
下面这个方法c++/c都可以。
setw(函数可以了解一下)


#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int a[3] = {1,2,3};
    for (int i = 0; i < 3; i++)
    {
        cout << setw(2) << a[i];     //setw(n)
    }
    return 0;
}

img


c语言的话,printf("%d "a);即可。

1.

打印的时候每个三个字符都加个空格。 你要不直接把代码贴出来

printf("%d ",t)
你加个空格呗

供参考:

#include <stdio.h>
int isPrime(int n)
{
    int i;
    if (n <= 3) return  n > 1;
    for (i = 2; i * i <= n; i++)
        if (n % i == 0) return 0;
    return 1;
}
int main()
{
    int cnt, i;
    for (i = 100, cnt = 0; i <= 200; i++) {
        if (isPrime(i))
            printf(cnt++ == 0 ? "%d" : " %d", i);
    }
    printf("\ncount=%d", cnt);
    return 0;
}

%d后面加个空格printf("%d "a);你也可以试一下:cout<<a<<' ';