0 0 Pavanagg Asked: May 22, 20222022-05-22T22:41:40+05:30 2022-05-22T22:41:40+05:30In: C language How do you program a simple calculator in C? 0 0 How do you program a simple calculator in C? c language Share Facebook 1 Answer Voted Oldest Recent ADMIN 2 2022-05-22T22:53:10+05:30Added an answer on May 22, 2022 at 10:53 pm Code: #include <stdio.h> int main() { char operator; double first, second; printf("Enter an operator (+, -, , /): "); scanf("%c", &operator); printf("Enter two operands: "); scanf("%lf %lf", &first, &second); switch(operator) { 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; // when operator doesn't match any case constant default: printf("Error! operator is not correct"); } } Leave an answerCancel replyYou must login to add an answer. Username or email* Password* Remember Me! Forgot Password?
Code: