Write C++ program by using while loop to display the following output
+---------+
| * |
| /*\ |
| //*\\ |
| ///*\\\ |
| \\\*/// |
| \\// |
| \*/ |
| * |
+---------+
| \\\*/// |
| \\// |
| \*/ |
| * |
| * |
| * |
| /*\ |
| //*\\ |
| ///*\\\ |
+---------+
#include <iostream>
using namespace std;
int main() {
int n = 4;
int i, j, k;
cout << '+';
i = 0;
while (i < 2*n+1) {
cout << '-';
i++;
}
cout << '+' << endl;
i = n;
while (i > 0) {
cout << '|';
j = 0;
while (j++ < i)
cout << ' ';
j = 0;
while (j++ < n-i)
cout << '/';
cout << '*';
j = 0;
while (j++ < n-i)
cout << '\\';
j = 0;
while (j++ < i)
cout << ' ';
cout << '|' << endl;
i--;
}
i = 1;
while (i <= n) {
cout << '|';
j = 0;
while (j++ < i)
cout << ' ';
j = 0;
while (j++ < n-i)
cout << '\\';
cout << '*';
j = 0;
while (j++ < n-i)
cout << '/';
j = 0;
while (j++ < i)
cout << ' ';
cout << '|' << endl;
i++;
}
cout << '+';
i = 0;
while (i < 2*n+1) {
cout << '-';
i++;
}
cout << '+' << endl;
i = 1;
while (i <= n) {
cout << '|';
j = 0;
while (j++ < i)
cout << ' ';
j = 0;
while (j++ < n-i)
cout << '\\';
cout << '*';
j = 0;
while (j++ < n-i)
cout << '/';
j = 0;
while (j++ < i)
cout << ' ';
cout << '|' << endl;
i++;
}
cout << '|';
j = 0;
while (j++ < n)
cout << ' ';
cout << '*';
j = 0;
while (j++ < n)
cout << ' ';
cout << '|' << endl;
i = n;
while (i > 0) {
cout << '|';
j = 0;
while (j++ < i)
cout << ' ';
j = 0;
while (j++ < n-i)
cout << '/';
cout << '*';
j = 0;
while (j++ < n-i)
cout << '\\';
j = 0;
while (j++ < i)
cout << ' ';
cout << '|' << endl;
i--;
}
cout << '+';
i = 0;
while (i < 2*n+1) {
cout << '-';
i++;
}
cout << '+' << endl;
return 0;
}
Comments
Leave a comment