The_Law

Untitled

Dec 7th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5.  
  6. int mode = 0;
  7.  
  8. void
  9. sigint_handler(int signo)
  10. {
  11.     mode = 0;
  12.     signal(SIGINT, sigint_handler);
  13. }
  14.  
  15. void
  16. sigquit_handler(int signo)
  17. {
  18.     mode = 1;
  19.     signal(SIGQUIT, sigquit_handler);
  20. }
  21.  
  22. int
  23. main(void)
  24. {
  25.     signal(SIGINT, sigint_handler);
  26.     signal(SIGQUIT, sigquit_handler);
  27.     printf("%d\n", getpid());
  28.     fflush(stdout);
  29.     int res = 0;
  30.     int curr;
  31.     while (scanf("%d", &curr) == 1) {
  32.         res = mode ? res * curr : res + curr;
  33.         printf("%d\n", res);
  34.         fflush(stdout);
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment