我似乎无法弄清楚这个嵌套循环模式C ++

时间:2017-03-08 09:19:21

标签: c++

//DrawTriangle("VOTE", true)
E
TE
OTE
VOTE

我想通了:

//DrawTriangle("VOTE", false)
VOTE
OTE
TE
E

这是我到目前为止所得到的:

            cout << "Please enter your WORD: ";
            cin >> word;
            cout << endl;

            int wordLength = word.length();

            //UP TRI WORD
            if (trDirection == 1)
            {
                //UP TRI TO DO
            }

            //DOWN TRI WORD 
            else if (trDirection == 2)
            {
                for (int row = 0; row <= wordLength; row++)
                {
                    for (int i = row; i < wordLength; i++)
                    {
                        cout << word[i];
                    }
                    cout << endl;
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

您想要反转序列 - 所以只需反转外部循环:

for (int row = wordLength; row >= 0; row--)