From b3c4b5e81ea94a9b0cdad2c0280e71b14242fff7 Mon Sep 17 00:00:00 2001 From: Atlas Cove Date: Tue, 28 Jun 2022 21:05:34 +0100 Subject: [PATCH] Added modulo program --- Makefile | 2 +- mod.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 mod.c diff --git a/Makefile b/Makefile index 77a4663..cd0a490 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -files = add div mean mul sub sum +files = add div mean mod mul sub sum all: $(files) diff --git a/mod.c b/mod.c new file mode 100644 index 0000000..56a9434 --- /dev/null +++ b/mod.c @@ -0,0 +1,25 @@ +#include +#ifndef eprintf +#define eprintf(...) fprintf(stderr, __VA_ARGS__) +#endif + +int main(int argc, char **argv) { + int v1; + int v2; + int out; + int e1; + int e2; + + e1 = sscanf(argv[1], "%i", &v1); + e2 = sscanf(argv[2], "%i", &v2); + if(e1==EOF) { + eprintf("%s: argument 1 cannot be parsed as int", *argv); + return 1; + } else if(e2==EOF) { + eprintf("%s: argument 2 cannot be parsed as int", *argv); + return 1; + } + out=v1%v2; + printf("%d\n",out); + return 0; +}