我想创建一个程序,它使用两个 for 语句来显示如下所示的星号模式。
**
****
******
********
**********
我可以让他们使用相当多的 for 语句,但我只想使用其中的 2 个,以使其更短,这就是我所拥有的:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int row = 1;
int astrk = 1;
for ( int row = 1; row < 2; row += 1)
{
for ( int astrk = 1; astrk <= 2; astrk += 1)
cout << '*';
cout << endl;
}// end for
for ( int row = 1; row < 2; row += 1)
{
for ( int astrk = 1; astrk <= 4; astrk +=1)
cout << '*';
cout << endl;
}//end for
for ( int row = 1; row < 2; row += 1)
{
for ( int astrk = 1; astrk <= 6; astrk += 1)
cout << '*';
cout << endl;
}// end for
for ( int row = 1; row < 2; row += 1)
{
for ( int astrk = 1; astrk <= 8; astrk += 1)
cout << '*';
cout << endl;
}// end for
for ( int row = 1; row < 2; row += 1)
{
for ( int astrk = 1; astrk <= 10; astrk += 1)
cout << '*';
cout << endl;
}// end for
return 0;
}
请帮忙?:)