blob: db7866413ea37d75842cd17f45f910b7d14d4644 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <u.h>
#include <libc.h>
double
roundf(double n)
{
return floor(n + 0.5);
}
int
roundi(double n)
{
return n+0.5;
}
void
usage(void)
{
fprint(2, "usage: %s number\n", argv0);
exits("usage");
}
void
main(int argc, char *argv[])
{
double n;
ARGBEGIN{
default: usage();
}ARGEND;
if(argc != 1)
usage();
n = strtod(argv[0], nil);
print("%g\n", roundf(n));
print("%d\n", roundi(n));
exits(0);
}
|