X-Git-Url: http://git.thejh.net/?p=tools.git;a=blobdiff_plain;f=math%2Fround.c;fp=math%2Fround.c;h=e422fd0ce216147856f5ed2ddc3ee4871e1f85c2;hp=0000000000000000000000000000000000000000;hb=7ebc44a8d838298394178687975cf9d2994ff8be;hpb=86973028b439986f4b2a7722c92e44c643ff5869 diff --git a/math/round.c b/math/round.c new file mode 100644 index 0000000..e422fd0 --- /dev/null +++ b/math/round.c @@ -0,0 +1,16 @@ +#include +#include + +int main(int argc, char **argv) { + if (argc != 2) xperror("invocation: round ", 0); + double target = strtod(argv[1], NULL); + char line[128]; + while (fgets(line, sizeof(line), stdin)) { + double n = strtod(line, NULL); + double quot = n / target; + quot = round(quot); + n = quot * target; + printf("%f\n", n); + } + return 0; +}