#include <stdio.h>
int main() {
char operator;
int num1, num2;
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
switch (operator) {
case '+':
printf("Result: %d + %d = %d\n", num1, num2, num1 + num2);
break;
case '-':
printf("Result: %d - %d = %d\n", num1, num2, num1 - num2);
break;
case '*':
printf("Result: %d * %d = %d\n", num1, num2, num1 * num2);
break;
case '/':
if (num2 != 0) {
printf("Result: %d / %d = %.2f\n", num1, num2, (float)num1 / num2);
} else {
printf("Error: Division by zero!\n");
}
break;
default:
printf("Error: Invalid operator!\n");
break;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: