我试图弄清楚该程序中的第一颗星星是如何打印的。当第一次遇到控制恒星的循环时,由于该循环的初始化,恒星的值应为1,而光的值应为零,因为在光的声明中它的赋值为零。打印出第一个星星的条件是(stars

#include <iostream>

using namespace std;

int main()
{
int empty = 10; // stars intial value
int light = 0;  // space inital value
int lines;      // number of lines on screen
int stars;      // number of stars each iteration
int spaces;     // number of spaces each iteration

for(lines = 0; lines <= 10; lines++)          // number of lines
{
    for(spaces = empty; spaces > 0; spaces--) // number of spaces
    {
        cout << " ";
    }

    for(stars = 1;  stars < light; stars++)    // number of stars
    {
        cout << "*";
    }

    cout << endl;

    light += 2;
    empty--;
}
}

最佳答案

它在第二次迭代中打印它。

当光等于2时,它将打印1星。

关于c++ - 如何打印该程序中的第一颗星星?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7827714/

10-10 08:54