fork download
  1. // C Program to make a Simple Calculator using
  2. // switch-case statements
  3. #include <stdio.h>
  4. #include <float.h>
  5.  
  6. int main() {
  7. char op='+';
  8. double a=10.5, b=5.4, res;
  9.  
  10. // Read the operator
  11. // printf("Enter an operator (+, -, *, /): ");
  12. // scanf("%c", &op);
  13.  
  14. // // Read the two numbers
  15. // printf("Enter two operands: ");
  16. // scanf("%lf %lf", &a, &b);
  17.  
  18. // Define all four operations in the corresponding
  19. // switch-case
  20. switch (op) {
  21. case '+':
  22. res = a + b;
  23. break;
  24. case '-':
  25. res = a - b;
  26. break;
  27. case '*':
  28. res = a * b;
  29. break;
  30. case '/':
  31. res = a / b;
  32. break;
  33. default:
  34. printf("Error! Incorrect Operator Value\n");
  35. res = -DBL_MAX;
  36. }
  37. if(res!=-DBL_MAX)
  38. printf("%.2lf", res);
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
15.90