Use nested while loop to print this shape
+----------+
| ^^ |
| ^ ^ |
| ^ ^ |
| ^^ |
| ^ ^ |
| ^ ^ |
+----------+
|v v|
| v v |
| vv |
|v v|
| v v |
| vv |
+----------+
#include<iostream>
using namespace std;
int main()
{
for (int i = 0; i < 10; i++)
{
if (i == 0 || i == 9)cout << "+";
else
cout << "-";
}
cout << endl;
for (int i = 0; i < 6; i++)
{
if (i %3==0)cout << "| ^^ |"<<endl;
else
cout << "| ^ ^ |"<<endl;
}
for (int i = 0; i < 10; i++)
{
if (i == 0 || i == 9)cout << "+";
else
cout << "-";
}
cout << endl;
for (int i = 0; i < 6; i++)
{
if (i % 3 == 0)cout << "|v v|" << endl;
else if (i % 3 == 1)
cout << "| v v |" << endl;
else
cout << "| vv |" << endl;
}
for (int i = 0; i < 10; i++)
{
if (i == 0 || i == 9)cout << "+";
else
cout << "-";
}
cout << endl;
}
Comments
Leave a comment