0
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循環
我有問題就在這裏,當我step into
的for loop
首次,沒有任何反應,對於第二個for loop step is applied
如:if I pass 1 to n
then:
mid_pos = 1; left_spaces = 0; line_stars = 1;
它進入循環內部: left_spaces = -1; line_stars = 3;
的for loop
打印3星級,它應該只打印1
我很困惑,我會很感激,如果任何人能幫助。
OMG,謝謝你,我的眼睛正在失明! – MTVS
小提示:'for(line_stars,left_spaces;' - 除了佔用線上的空間外,這絕對沒有任何用處,如果你沒有任何東西需要初始化, –