Advertisement
Md_hosen_zisad

operator

Aug 6th, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. # include <stdio.h>
  2. #include<math.h>
  3.  
  4. int main() {
  5.  
  6.     char operator;
  7.     double firstNumber,secondNumber;
  8.  
  9.     printf("Enter an operator (+, -, *,/): ");
  10.     scanf("%c", &operator);
  11.  
  12.     printf("Enter two operands: ");
  13.     scanf("%lf %lf",&firstNumber, &secondNumber);
  14.  
  15.     switch(operator)
  16.     {
  17.         case '+':
  18.             printf("%.1lf + %.1lf = %.1lf",firstNumber,secondNumber, firstNumber + secondNumber);
  19.             break;
  20.  
  21.         case '-':
  22.             printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber - secondNumber);
  23.             break;
  24.  
  25.         case '*':
  26.             printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber * secondNumber);
  27.             break;
  28.  
  29.         case '/':
  30.             printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber / secondNumber);
  31.             break;
  32.  
  33.  
  34.         default:
  35.             printf("Error! operator is not correct");
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement