Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int     doop(char *s1, char *s2, char *s3)
  5. {
  6.     if (s2[0] == '+')
  7.         return (atoi(s1) + atoi(s3));
  8.     if (s2[0] == '-')
  9.         return (atoi(s1) - atoi(s3));
  10.     if (s2[0] == '*')
  11.         return (atoi(s1) * atoi(s3));
  12.     if (s2[0] == '/')
  13.         return (atoi(s1) / atoi(s3));
  14.     if (s2[0] == '%')
  15.         return (atoi(s1) % atoi(s3));
  16.     return (0);
  17. }
  18.  
  19. int     main(int ac, char **av)
  20. {
  21.     if (ac == 4)
  22.         return (printf("%d\n", doop(av[1], av[2], av[3])));
  23.     return (printf("\n"));
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement