initial commit

This commit is contained in:
Atlas Cove 2022-05-07 13:22:36 +01:00
commit 244862feea
7 changed files with 141 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
add
div
mean
mul
sub
sum

25
add.c Normal file
View 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 %d cannot be parsed as int", *argv);
return 1;
} else if(e2==EOF) {
eprintf("%s: argument %d cannot be parsed as int", *argv);
return 1;
}
out=v1+v2;
printf("%d\n",out);
return 0;
}

25
div.c Normal file
View 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 %d cannot be parsed as int", *argv);
return 1;
} else if(e2==EOF) {
eprintf("%s: argument %d cannot be parsed as int", *argv);
return 1;
}
out=v1/v2;
printf("%d\n",out);
return 0;
}

18
mean.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
int main(int argc, char **argv) {
int buf;
int acc;
int err;
for(int i=1;i<argc;i++) {
err=sscanf(argv[i], "%i", &buf);
if(err!=1) {
fprintf(stderr, "%s: arg #%d not an integer.\n",*argv,i);
return 1;
}
acc+=buf;
}
acc/=argc-1;
printf("%d\n",acc);
return 0;
}

25
mul.c Normal file
View 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 %d cannot be parsed as int", *argv);
return 1;
} else if(e2==EOF) {
eprintf("%s: argument %d cannot be parsed as int", *argv);
return 1;
}
out=v1*v2;
printf("%d\n",out);
return 0;
}

25
sub.c Normal file
View 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 %d cannot be parsed as int", *argv);
return 1;
} else if(e2==EOF) {
eprintf("%s: argument %d cannot be parsed as int", *argv);
return 1;
}
out=v1-v2;
printf("%d\n",out);
return 0;
}

17
sum.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
int main(int argc, char **argv) {
int buf;
int acc;
int err;
for(int i=1;i<argc;i++) {
err=sscanf(argv[i], "%i", &buf);
if(err!=1) {
fprintf(stderr, "sscanf error: not an integer.\n");
return 1;
}
acc+=buf;
}
printf("%d\n",acc);
return 0;
}