initial commit

master init
Atlas Cove 7 months ago
commit 244862feea
  1. 6
      .gitignore
  2. 25
      add.c
  3. 25
      div.c
  4. 18
      mean.c
  5. 25
      mul.c
  6. 25
      sub.c
  7. 17
      sum.c

6
.gitignore vendored

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

25
add.c

@ -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

@ -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;
}

@ -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

@ -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

@ -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

@ -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;
}
Loading…
Cancel
Save