Title:
Title description
Print n-order solid diamond
Input description:
Input an integer n, 0 <n <= 10
Output description:
output n-order solid rhombus, occupying 2*n-1 rows
Sample input
4
sample output
Code:
#include<iostream>
using namespace std;
int main() {
int n;
cin >> n;
// 上三角
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
// 打印空格
cout << " ";
}
for (int k = 1; k <= 2 * i - 1; k++) {
// 打印*
cout << "*";
}
for (int j = 1; j <= n - i; j++) {
// 打印空格
cout << " ";
}
cout << endl;
}
// 下三角
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
for (int k = 1; k <= 2 * i - 1; k++) {
cout << "*";
}
for (int j = 1; j <= n - i; j++) {
cout << " ";
}
cout << endl;
}
system("pause");
return 0;
}