Dimitrija

Laboratoriski 8 - 1 SP

Dec 18th, 2020
1,818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void matematickaOperacija (int a, int b, char operation, int *rezultat){
  4.  
  5. if (operation == '+'){
  6.     *rezultat=a+b;
  7. }
  8. else if (operation == '-'){
  9.     *rezultat=a-b;
  10. }
  11. else if (operation == '*'){
  12.     *rezultat=a*b;
  13. }
  14.  
  15. else if (operation == '/'){
  16.     *rezultat=a/b;
  17. }
  18. else if (operation == '%'){
  19.     *rezultat=a%b;
  20. }
  21.  
  22.  
  23. }
  24.  
  25. int main(){
  26.     int x,y,z;
  27.     scanf("%d %d",&x,&y);
  28.     matematickaOperacija(x,y,'+',&z);
  29.     printf("%d + %d -> %d\n",x,y,z);
  30.     matematickaOperacija(x,y,'-',&z);
  31.     printf("%d - %d -> %d\n",x,y,z);
  32.     matematickaOperacija(x,y,'*',&z);
  33.     printf("%d * %d -> %d\n",x,y,z);
  34.     matematickaOperacija(x,y,'/',&z);
  35.     printf("%d / %d -> %d\n",x,y,z);
  36.     matematickaOperacija(x,y,'%',&z);
  37.     printf("%d %% %d -> %d\n",x,y,z);
  38.    
  39.     return 0;
  40.  
  41. }  
Advertisement
Add Comment
Please, Sign In to add comment