I'm trying to come up with a program that will display the following pattern with a loop:
+
++
+++
++++
+++++
I wrote something that works, but I feel like there should be an easier way but I cannot figure out how. Please point me to the right direction. Help is much appreciated. Here's what I have:
#include <iostream>
usingnamespace std;
int main ( )
{
// Grouping the rows of Pattern A into a single loop
for (int A = 0; A < 1; A++)
{
// Defining counter variable for the number of + displayed
int plus;
//Setting the number of + displayed per row
for (plus = 0; plus < 11; plus++)
{
cout << "+";
if (plus == 0) // row 1
break;
}
cout << endl;
for (plus = 0; plus < 12; plus++)
{
cout << "+";
if (plus == 1) // row 2
break;
}
cout << endl;
for (plus = 0; plus < 12; plus++)
{
cout << "+";
if (plus == 2) // row 3
break;
}
cout << endl;
for (plus = 0; plus < 12; plus++)
{
cout << "+";
if (plus == 3) // row 4
break;
}
cout << endl;
for (plus = 0; plus < 12; plus++)
{
cout << "+";
if (plus == 4) // row 5
break;
}
cout << endl;
}
return 0;
}