当前位置:C++技术网 > 精选软件 > C++ Primer Plus 6th 5.9 编程练习题 第10题 分多行打印点号和星号

C++ Primer Plus 6th 5.9 编程练习题 第10题 分多行打印点号和星号

更新时间:2019-05-03 13:18:54浏览次数:1+次

题目:
10.编写一个使用嵌套循环的程序,要求用户输入一个值,指出要显示多少行。然后,程序将显示相应行数的星号,其中第一行包括一个星号,第二行包括两个星号,依此类推。每一行包含的字符数等于用户指定的行数,在星号不够的情况下,在星号前面加上句点。该程序的运行情况如下:

Enter  number  of  rows :  5
....*
...**
..***
.****
*****

答案:  书上无答案。

C++技术网辅导详解解答:
    参考代码:

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int row;
    cout << "Enter number of rows :";
    cin >> row;
    for (int i = 0; i < row; i++)
    {
        for (int j = 1; j < row - i; j++)
        {
            cout << ".";
        }
        for (int m = 0; m <= i; m++)
        {
            cout << "*";
        }
        cout << endl;
    }
    return 0;
}