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);
}
...
我在这里遇到问题,当我step into
第for loop
一次时,什么都没有发生,第二次for loop step is applied
例如:如果我pass 1 to n
那么:
mid_pos =1; left_spaces=0; line_stars=1;
它进入循环内部:left_spaces=-1; line_stars=3;
for loop
打印 3 颗星,它应该只打印 1 颗星。
我很困惑,如果有人可以提供帮助,我将不胜感激。