i want to create a program that uses two for statements to display the pattern of asterisks shown below.
**
****
******
********
**********
i can make them using quite a few for statements but i only want to use 2 of them, to make it shorter
this is what i have:
#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;
}
help please? 🙂
You should rewrite this using two
forloops, once controlling the rows, and the other one controlling the column.You have 5 rows, and on each row, you have 2, 4, 6, etc… stars.
Try to understand your problem, figure out a solution on paper and then try to implement it, it will be way simpler if you’re learning how to program.