Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. int main(void)
  7. {
  8. char *str = malloc(2000*sizeof(*str));
  9. char *beg = str;
  10. char *endp;
  11. int sum;
  12. double mul;
  13. int c = getchar();
  14. while(c != EOF)//'q' equ EOF
  15. {
  16. sum = 0;
  17. mul = 1.0;
  18. while(c != '\n' && c !=EOF)
  19. {
  20. *str = (char)c;
  21. str++;
  22. c = getchar();
  23. }
  24. *str = '\0';
  25. str = beg;
  26. sum = 0;
  27. mul = 1.0;
  28. while(*str)
  29. {
  30. while (isspace(*str) && *str!='\0') str++;
  31. long num = strtol(str, &endp, 10);
  32. if(*endp == '.')
  33. {
  34. double ssd = strtod(str, &endp);
  35. mul *= ssd;
  36. } else sum += num;
  37. str = endp+1;
  38. while (isspace(*str) && *str!='\0') str++;
  39. }
  40. printf("%ld %.10g\n", sum, mul);
  41. if (c!=EOF) c=getchar();
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement