小编Moh*_*med的帖子

打印没有嵌套条件的三角形

#include<iostream>

using namespace std;
int main() {
    int height, star{ 0 };
    cout << "Enter height of triangle";
    cin >> height;
    for(int i=1; i<=height; i++)
    {
        if(star<i)
        {
            cout << "*";
            ++star;
            continue;
        }
        cout << endl;
        star = 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是在一行中打印星星,我想在第一行打印一颗星星,然后在第二行打印 2 颗星,依此类推。

例子:

*
**
***
****
Run Code Online (Sandbox Code Playgroud)

图片:

在此处输入图片说明

c++ loops

5
推荐指数
1
解决办法
116
查看次数

标签 统计

c++ ×1

loops ×1