Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- int main(int argc, char *argv[]) {
- if (argc & 1) {
- fprintf(stderr, "arg error!\n");
- exit(-1);
- }
- int sum = strtol(argv[1], NULL, 10);
- for (int i = 2; i < argc; i++) {
- int sign = 1, nr;
- if (*argv[i] == '-') {
- sign = -1;
- }
- i++;
- nr = strtol(argv[i], NULL, 10);
- nr *= sign;
- sum += nr;
- }
- printf("result: %d\n", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement