Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- int main(void)
- {
- char *str = malloc(2000*sizeof(*str));
- char *beg = str;
- char *endp;
- int sum;
- double mul;
- int c = getchar();
- while(c != EOF)//'q' equ EOF
- {
- sum = 0;
- mul = 1.0;
- while(c != '\n' && c !=EOF)
- {
- *str = (char)c;
- str++;
- c = getchar();
- }
- *str = '\0';
- str = beg;
- sum = 0;
- mul = 1.0;
- while(*str)
- {
- while (isspace(*str) && *str!='\0') str++;
- long num = strtol(str, &endp, 10);
- if(*endp == '.')
- {
- double ssd = strtod(str, &endp);
- mul *= ssd;
- } else sum += num;
- str = endp+1;
- while (isspace(*str) && *str!='\0') str++;
- }
- printf("%ld %.10g\n", sum, mul);
- if (c!=EOF) c=getchar();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement