C++ 与for循环的条件和步骤的评估混淆 void draw_菱形(int n) { int mid_pos=ceil((双)n/2); int left_spaces=mid_pos-1; int line_stars=1; putchar(10); //从钻石的顶部到中间打印 对于(line_stars,左_空格;line_stars

C++ 与for循环的条件和步骤的评估混淆 void draw_菱形(int n) { int mid_pos=ceil((双)n/2); int left_spaces=mid_pos-1; int line_stars=1; putchar(10); //从钻石的顶部到中间打印 对于(line_stars,左_空格;line_stars,c++,c,for-loop,step-into,C++,C,For Loop,Step Into,Uh哦,请注意狡猾的分号: void draw_diamond(int n) { int mid_pos = ceil((double)n / 2); int left_spaces = mid_pos-1; int line_stars = 1; putchar(10); //printing from top through the middle of the diamond for(line_stars, left_spaces ; line_stars <= n; line_st

Uh哦,请注意狡猾的分号:

void draw_diamond(int n)
{
int mid_pos = ceil((double)n / 2);
int left_spaces = mid_pos-1;
int line_stars = 1;

putchar(10);
//printing from top through the middle of the diamond
for(line_stars, left_spaces ; line_stars <= n; line_stars+=2, left_spaces--);
{
    //printing the left_spaces
    for(int i=1; i<=left_spaces; i++)
        putchar(32);

    //printing the line_stars
    for(int i=1; i<=line_stars; i++)
        putchar('*');
    putchar(10);
}

for(line_-stars,left_-spaces;line_-stars噢,小心那鬼鬼祟祟的分号:

void draw_diamond(int n)
{
int mid_pos = ceil((double)n / 2);
int left_spaces = mid_pos-1;
int line_stars = 1;

putchar(10);
//printing from top through the middle of the diamond
for(line_stars, left_spaces ; line_stars <= n; line_stars+=2, left_spaces--);
{
    //printing the left_spaces
    for(int i=1; i<=left_spaces; i++)
        putchar(32);

    //printing the line_stars
    for(int i=1; i<=line_stars; i++)
        putchar('*');
    putchar(10);
}
for(line_stars,left_spaces;line_stars次要建议:
for(line_stars,left_spaces;
)-除了占用行上的空间之外,这绝对没有任何作用。如果行上没有任何要初始化的内容,请使用
for(;…
。次要建议:
for(行为星形,左为空格;
-除了占用行上的空间外,这完全不起任何作用。如果行上没有要初始化的内容,请使用(;…
)。