回答編集履歴
1
rewrite answer
answer
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
|
1
|
+
整数`n`の20%、つまり`n / 5`の切り上げは`(n + 4) / 5`(全てint型で計算)で求まります。
|
2
2
|
|
3
|
-
```
|
3
|
+
```
|
4
4
|
#include <assert.h>
|
5
5
|
#include <stdio.h>
|
6
6
|
|
7
7
|
int ceil20up(int n)
|
8
8
|
{
|
9
9
|
assert(0 <= n);
|
10
|
+
int r = (n + 4) / 5; // ceil(n * 20%)
|
10
|
-
return
|
11
|
+
return n + r;
|
11
12
|
}
|
12
13
|
|
13
14
|
int main()
|
14
15
|
{
|
15
16
|
for (int i = 1; i <= 100; i++)
|
16
|
-
printf("%d->%d\n", i, ceil20up(i));
|
17
|
+
printf("%d -> %.1f -> %d\n", i, i * 1.2, ceil20up(i));
|
17
18
|
}
|
18
19
|
```
|