Tuesday, January 17, 2023

Simple calculator 2.0


Hey there recently i added some fixes to this code. But now for this we have  a new and easy code for this simple calculator. here is the code.


#include <stdio.h>

int main()

{

  char op;

  double first, second;

  printf("Enter an operator (+, -, *, /): ");

  scanf("%c", &op);

  printf("Enter two operands: ");

  scanf("%lf %lf", &first, &second);

  switch (op) 

  {

    case '+':

      printf("%.1lf + %.1lf = %.1lf", first, second, first + second);

      break;

    case '-':

      printf("%.1lf - %.1lf = %.1lf", first, second, first - second);

      break;

    case '*':

      printf("%.1lf * %.1lf = %.1lf", first, second, first * second);

      break;

    case '/':

      printf("%.1lf / %.1lf = %.1lf", first, second, first / second);

      break;

    default:

      printf("Error! operator is not correct");

  }


  return 0;

}


0 comments:

Post a Comment

Contact Us

Phone :

+8801716815647
+8801996204467
+8801520731186

Email :

susmoy1025@gmail.com
dishantanjim@gmail.com
sadmansakib7494@gmail.com