calc

Home


WeChat: cstutorcs
QQ: 749389476
# include
int main() {
char operator;
int firstNumber,secondNumber;

printf(“Enter an operator (+, -, *, /): “);
scanf(” %c”, &operator);
printf(“Enter two operands: “);
scanf(“%d %d”, &firstNumber, &secondNumber);
switch (operator) {
printf(“%d + %d = %d\n”,firstNumber, secondNumber, firstNumber + secondNumber);
printf(“%d – %d = %d\n”,firstNumber, secondNumber, firstNumber – secondNumber);
printf(“%d * %d = %d\n”,firstNumber, secondNumber, firstNumber * secondNumber);
printf(“%d / %d = %d\n”,firstNumber, secondNumber, firstNumber / secondNumber); // Divide by zero
printf(“Error! operator is not correct”);
} while(1);