如何将变量放在嵌套循环中?

How to put variable on nested loop?

我想制作一盒变量。不知道哪里出错了?

int i;

for(i=0;i<=w;i++) {
    printf("%c ",c);
    int j;
    for(j=0;j<=h;j++){
        printf("%c ",c);
    }
    printf("\n");
}

我想要这样的输出:

L L L L L
L L L L L
L L L L L

这是您的代码的修改版本(代码中的注释指出了我所做的更改):

int i;
for(i=0;i<h;i++){ //changed <= to < (since i is starting from 0) or it would've printed an extra row of L's
    //also, it should be i<h not i<w (considering h is the height of the rectangle)
    //removed printf("%c ",c); from here as well to avoid printing an extra L at the beginning of each row
    int j;
    for(j=0;j<w;j++){ //changed <= to < in this case too or it would've printed an extra L at the end of each row
    //changed j<h to j<w as well (considering w is the width of the rectangle)
        printf("%c ",c);
    }
    printf("\n");
}