天空不留下鸟的痕迹,但我已飞过.
我也帖一个,可能有点麻烦,高手们能帮我优化一下吗~~因为我也刚学不久哈.. #include <iostream> using namespace std;
int main() { int n, i, j; cout << "Enter the max number: "; cin >> n; for (i = 1; i <= n; i++) { for (j = n - i; j > 0; j--) cout << " "; for (j = 1; j <= i; j++) cout << j; if (j > 1) { for (int k = i - 1; k > 0; k--) cout << k; } cout << endl; } for (i = n - 1; i > 0; i--) { for (j = 1; j <= n - i; j++) cout << " "; for (j = 1; j <= i; j++) cout << j; if (j > 1) { for (int k = i - 1; k > 0; k--) cout << k; } cout << endl; } system("pause"); return 0; }