Emon766

operator use switch

Mar 3rd, 2021 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. double a,b;
  6. char choice;
  7.  
  8. scanf("%c" ,&choice);
  9. scanf("%lf %lf",&a ,&b);
  10.  
  11. switch (choice)
  12. {
  13.  
  14. case '*':
  15.     printf("%.2lf\n", a*b);
  16.     break;
  17.  
  18. case '+':
  19.     printf("%.2lf\n",a+b);
  20.     break;
  21.  
  22. case '-':
  23.     printf("%.2lf\n",a-b);
  24.     break;
  25.  
  26. case '/':
  27.     printf("%.2lf\n",a/b);
  28.     break;
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Add Comment
Please, Sign In to add comment