---
# System prepended metadata

title: Print Star with while
tags: [實習額外加分題]

---

###### tags: `實習額外加分題`

Print Star with while
===
<!-- 
## Video

{%youtube xgJVX8kamN8 %}
---
-->

## Description
請先輸入一個數字，並印出如下的三角形。

* 規定條件
    * 每行最後面不能有空白
    * 最後一行後面沒有換行
    * 請用 for-loop 做!

* 小提示
    * 請切記迴圈三要素
        * 初值
        * 條件
        * 步進
---

## Sample input 1
5

## Sample output 1

![](https://i.imgur.com/coGfWg3.png)


---

## Sample input 2
10

## Sample output 2

![](https://i.imgur.com/lJ2jf08.png)

---

## 錯誤輸出案例

最後一行輸出完之後不應該換行，且每一行最後一個 * 最後不應該有空白

![](https://i.imgur.com/RuUBvt0.png)

<!-- 
    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;
    }
 
-->


