---
# System prepended metadata

title: 16-4 1到N之和
tags: [DICE C]

---

---
tags: DICE C
---

16-4 1到N之和
===

> [name=CHAWTeam]

---

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

---

題目
--

```!
輸入一整數n，
計算整數1到n，公差為1的累加和。
如1+2+3+...+n的和，n>1。

輸入範例:
99

輸出範例:
4950
```

程式碼
--

```c=

#include <stdio.h>

int main()
{
    int n, sum = 0;
    scanf("%d", &n);
    for (int i = 1; n >= i; i++)
        sum += i;
    printf("%d", sum);
    return 0;
}

```

執行
--

```!
99
4950
```

---

[查看我們在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-16-4" width="100%"></iframe>

---

{%hackmd i1nMRrZcTFmTvoF897K9zg %}