// chapter07a01图案打印.cpp
//双循环-嵌套循环
//外层循环控制行(行数、换行)
//内层循环控制列(列数、列的图行)
using namespace std;
int main()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j <= 2 * i ; j++)
{
cout << "*";
}
cout << endl;
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f9bd7237430fc19243d1d5616b04f4e7.png)
// chapter07a01图案打印.cpp
//双循环-嵌套循环
//外层循环控制行(行数、换行)
//内层循环控制列(列数、列的图行)
using namespace std;
int main()
{
//图形上半部分
for (int i = 0; i < 4; i++)
{
for (int j = 0; j <= 2 - i; j++)
{
cout << " ";
}
for (int j = 0; j <= 2 * i; j++)
{
cout << "*";
}
cout << endl;
}
//图形下半部分(行数,星星的个数)
for (int i = 0; i < 3; i++)
{
for (int j = 0; j <= i; j++)
{
cout << " ";
}
for (int j = 0; j <= 4 - 2 * i; j++)
{
cout << "*";
}
cout << endl;
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/56ab0dd465ca9c8cf24d84a01d20ecf0.png)
using namespace std;
int main()
{
//图形上半部分
for (int i = 0; i < 4; i++)
{
for (int j = 0; j <= 2 - i; j++)
{
cout << " ";
}
for (int j = 0; j <= 2 * i; j++)
{
cout << char('A' + i);
}
cout << endl;
}
//图形下半部分(行数,星星的个数)
for (int i = 0; i < 3; i++)
{
for (int j = 0; j <= i; j++)
{
cout << " ";
}
for (int j = 0; j <= 4 - 2 * i; j++)
{
cout << char('C' - i);
}
cout << endl;
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bb0b6cf064e6e823029f7eadc8df661d.png)
using namespace std;
int main()
{
//图形上半部分
for (int i = 0; i < 4; i++)
{
//在j是极值的时候打印'*'号,其余时候打印空格
for (int j = 0; j <= 2 - i; j++)
{
cout << " ";
}
for (int j = 0; j <= 2 * i; j++)
{
if (j == 0 || j == 2 * i)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
//图形下半部分(行数,星星的个数)
for (int i = 0; i < 3; i++)
{
for (int j = 0; j <= i; j++)
{
cout << " ";
}
for (int j = 0; j <= 4 - 2 * i; j++)
{
if (j == 0 || j == 4 - 2 * i)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fff351e04fa0c7aecbb476682a238470.png)