# 數字塔 https://neoj.sprout.tw/problem/893/ ### 題目敘述 請讀入一個數字n,並輸出如範例所示的數字塔 ### 輸入說明 輸入有一個正整數n $1≤n≤9$ ### 輸出說明 請輸出如範例的數字塔,共有n層 注意:每一層最後面不需要空白,直接換行即可 ### 範例輸入 ``` 5 ``` ### 範例輸出 ``` 1 1 22 22 333 333 4444 4444 55555 55555 ``` # Code ```cpp #include <iostream> using namespace std; int main(){ int x, j=1; cin>>x; while (j <= x) { int i = 1, k = 1, l = 1; while (i <= x - j) { cout << " "; i++; } while (k <= j) { cout << j; k++; } cout << " "; while (l <= j) { cout << j; l++; } cout << "\n"; j++; } }
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up