pranjal1805

Untitled

Apr 6th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.     int a,b,result;
  6.     char operator;
  7.     printf("Enter two integers: ");
  8.     scanf("%d %d", &a, &b);
  9.     printf("Enter operation: ");
  10.     scanf(" %c", &operator);
  11.     switch(operator)
  12.     {
  13.         case '+':
  14.             result=a+b;
  15.             printf("Output: %d\n",result);
  16.             break;
  17.    
  18.         case '-':
  19.             result=a-b;
  20.             printf("Output: %d\n",result);
  21.             break;
  22.        
  23.         case '*':
  24.             result=a*b;
  25.             printf("Output: %d\n",result);
  26.             break;
  27.        
  28.         case '/':
  29.         {
  30.             switch(b)
  31.             {
  32.                 case 0:
  33.                     printf("ERROR: Divide by zero\n");
  34.                     break;
  35.                
  36.                 default:
  37.                     result=a/b;
  38.                     printf("Output: %d\n",result);
  39.             }
  40.         }
  41.         break;
  42.         default:
  43.             printf("%c is not a valid operation\n", operator);
  44.  
  45.     }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment