fork(1) download
  1.  
  2. #include <stdio.h>
  3.  
  4. int main() {
  5.  
  6. int i = 0;
  7. int a = 10;
  8. int b = 20;
  9. int f;
  10. float g;
  11. char ch;
  12.  
  13. for (int i = 0; i < 5; i++) {
  14.  
  15. printf("Enter math operation: \n");
  16. scanf("%c\n", &ch);
  17.  
  18. switch (ch) {
  19.  
  20. case '+':
  21. f = a + b;
  22. printf("f = %d\n", f);
  23. break;
  24. case '-':
  25. f = a - b;
  26. printf("f = %d\n", f);
  27. break;
  28. case '*':
  29. f = a * b;
  30. printf("f = %d\n", f);
  31. break;
  32. case '/':
  33. g = (float)a / (float)b;
  34. printf("f = %f\n", g);
  35. break;
  36. case '%':
  37. f = a % b;
  38. printf("f = %d\n", f);
  39. break;
  40. default:
  41. printf("invalid operator\n");
  42. break;
  43. }
  44.  
  45. }
  46.  
  47. return 0;
  48. }
  49.  
  50.  
Success #stdin #stdout 0s 10304KB
stdin
Standard input is empty
stdout
Enter math operation: 
invalid operator
Enter math operation: 
invalid operator
Enter math operation: 
invalid operator
Enter math operation: 
invalid operator
Enter math operation: 
invalid operator