---
# System prepended metadata

title: 21-10 算多少利息人都行
tags: [DICE C]

---

---
tags: DICE C
---

21-10 算多少利息人都行
===

> [name=CHAWTeam]

目錄：[DICE C語言程式破解](/@CHAWTeam/DiceC)

題目
---

```!
寫一個程式，計算銀行儲戶的複利表。

輸入年數、本金與年利率，輸出每年結算時帳戶的存款數，金額請四捨5入到小數點後第一位。

當年數為-1時，程式停止輸入。

年利率公式：本利和=原存款*(1+年利率)^年數

提示:
標準函式庫之pow可計算乘冪(指數)：pow(x,y)可計算出x之y次方值

輸入範例:
10
1000
0.05
5
1000
0.05
-1

輸出範例:
year  amount
1   1050.0
2   1102.5
3   1157.6
4   1215.5
5   1276.3
6   1340.1
7   1407.1
8   1477.5
9   1551.3
10 1628.9
year  amount
1   1050.0
2   1102.5
3   1157.6
4   1215.5
5   1276.3
```

程式碼
---

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

int main()
{
    int year;
    float deposit, rate;
    
    scanf("%d", &year);
    scanf("%f %f", &deposit, &rate);
    
    while (year != -1)
    {
        printf("year\tamount\n");
    
        for (int i = 1; i <= year; i++)
            printf("%d\t%.1f\n", i, deposit * pow(1 + rate, i));
        
        scanf("%d", &year);
        scanf("%f %f", &deposit, &rate);
    }
    
    return 0;
}
```

執行
---

### 輸入

```!
10
1000
0.05
5
1000
0.05
-1
```

### 輸出

```!
year  amount
1   1050.0
2   1102.5
3   1157.6
4   1215.5
5   1276.3
6   1340.1
7   1407.1
8   1477.5
9   1551.3
10 1628.9
year  amount
1   1050.0
2   1102.5
3   1157.6
4   1215.5
5   1276.3
```

---

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

---

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

---

{%hackmd i1nMRrZcTFmTvoF897K9zg %}