write A C++ program to display output using while loop only
+------+
| ^^ |
| ^ ^ |
|^ ^|
| ^^ |
| ^ ^ |
|^ ^|
+------+
|v v|
| v v |
| vv |
|v v|
| v v |
| vv |
+------+
#include <iostream>
using namespace std;
int main() {
int n = 3;
int i, j, k;
cout << '+';
i = 0;
while (i < 2*n) {
cout << '-';
i++;
}
cout << '+' << endl;
i = 0;
while (i < 2) {
j = 0;
while (j < n) {
cout << '|';
k = 0;
while (k < (n-j)/2) {
cout << ' ';
k++;
}
cout << '^';
k = 0;
while (k < j) {
cout << ' ';
k++;
}
cout << '^';
k = 0;
while (k < (n-j)/2) {
cout << ' ';
k++;
}
cout << '|' << endl;
j++;
}
i++;
}
cout << '+';
i = 0;
while (i < 2*n) {
cout << '-';
i++;
}
cout << '+' << endl;
i = 0;
while (i < 2) {
j = 0;
while (j < n) {
cout << '|';
k = 0;
while (k < (j+1)/2) {
cout << ' ';
k++;
}
cout << 'V';
k = 0;
while (k < n-j-1) {
cout << ' ';
k++;
}
cout << 'V';
k = 0;
while (k < (j+1)/2) {
cout << ' ';
k++;
}
cout << '|' << endl;
j++;
}
i++;
}
cout << '+';
i = 0;
while (i < 2*n) {
cout << '-';
i++;
}
cout << '+' << endl;
return 0;
}
Comments
Leave a comment