added back C version
This commit is contained in:
parent
10ab8da848
commit
b2ff6f88e3
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
#TODO: find way of installing shell library with make
|
||||
files = mean sum
|
||||
files = c/add c/div c/mean c/mod c/mul c/sub c/sum
|
||||
|
||||
all: $(files)
|
||||
|
||||
|
25
c/add.c
Normal file
25
c/add.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
25
c/div.c
Normal file
25
c/div.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
25
c/mod.c
Normal file
25
c/mod.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
25
c/mul.c
Normal file
25
c/mul.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
25
c/sub.c
Normal file
25
c/sub.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user