Advertisement
Guest User

Aritmetikai mûveletek

a guest
Feb 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. int a,b;
  8. char sz[10],*token,op[5];
  9.  
  10. while ( gets(sz) )
  11. {
  12.  
  13.  
  14.  
  15. token = strtok(sz," ");
  16. a= atoi(token);
  17.  
  18. token = strtok(NULL," ");
  19. strcpy(op,token);
  20.  
  21. token = strtok(NULL," ");
  22. b= atoi(token);
  23.  
  24. if ( a == 0 || b == 0 ) break;
  25.  
  26. if ( !strcmp(op,"+") ) printf("%d\n",a+b);
  27. else if ( !strcmp(op,"/") ) printf("%d\n",a/b);
  28. else if ( !strcmp(op,"*") ) printf("%d\n",a*b);
  29. else if ( !strcmp(op,"-") ) printf("%d\n",a-b);
  30. else if ( !strcmp(op,"%") ) printf("%d\n",a%b);
  31.  
  32.  
  33. }
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement