---
# System prepended metadata

title: 14_6 1到N的和
tags: [DICE C]

---

---
tags: DICE C
---

14_6 1到N的和
===

> [name=CHAWTeam]

---

目錄：[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)

---

題目
---

```!
寫一個程式，輸入正整數N，

請輸出1、1+2、1+2+3、...、1+2+3+..+N 累加的和。

輸入範例:
6

輸出範例:
1
3
6
10
15
21
```

程式碼
---

```c=
#include <stdio.h>

int main()
{
    int i = 1, j = 0, n;
    scanf("%d", &n);
    while (i <= n)
    {
        j += i;
        printf("%d\n", j);
        i++;
    }
    return 0;
}
```

輸出
---

```!
6
1
3
6
10
15
21
```

---

[查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam)
目錄：[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC)

---

{%hackmd Iiu5mOixR7yWkPHKCkabBg %}
<iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-14_6" width="100%"></iframe>

---

{%hackmd i1nMRrZcTFmTvoF897K9zg %}