#include <stdio.h>

int main() {

    char operator;
    double num1;
    double num2;
    double result;

    printf("\nEnter an operator (+ - * /): ");
    scanf(" %c", &operator); // Notice the space before %c to consume any leading whitespace

    printf("Enter number 1: ");
    scanf("%lf", &num1);

    printf("Enter number 2: ");
    scanf("%lf", &num2);

    switch(operator) {
        case '+':
            result = num1 + num2;
            printf("\nresult: %.2lf", result);
            break;

        case '-':
            result = num1 - num2;
            printf("\nresult: %.2lf", result);
            break;

        case '*':
            result = num1 * num2;
            printf("\nresult: %.2lf", result);
            break;

        case '/':
            if (num2 != 0) {
                result = num1 / num2;
                printf("\nresult: %.2lf", result);
            } else {
                printf("\nError: Division by zero!");
            }
            break;

        default:
            printf("\n%c is not a valid operator", operator);
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: