###### tags: `實習額外加分題` Print Star with while === <!-- ## Video {%youtube xgJVX8kamN8 %} --- --> ## Description 請先輸入一個數字,並印出如下的三角形。 * 規定條件 * 每行最後面不能有空白 * 最後一行後面沒有換行 * 請用 for-loop 做! * 小提示 * 請切記迴圈三要素 * 初值 * 條件 * 步進 --- ## Sample input 1 5 ## Sample output 1  --- ## Sample input 2 10 ## Sample output 2  --- ## 錯誤輸出案例 最後一行輸出完之後不應該換行,且每一行最後一個 * 最後不應該有空白  <!-- int a = 0; cin >> a; int i = 1, j = 1, k = 1; while(i <= a){ j = 1; while(j <= a-i){ cout << " "; j++; } k = 1; while(k <= i*2-1){ if(k % 2 == 1) cout << "*"; else cout << " "; k++; } if(i != a) { cout << endl; } i++; } return 0; for(int i=1;i<=a;i++) { for(int k = 1; k <= a-i; k++){ cout << " "; } for(int j=1;j<=i*2-1;j=j+1) { if(j % 2 == 1) cout << "*"; else cout << " "; } if(i != a) cout << endl; } -->
×
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