Open ManasZore opened 10 months ago
Calculator code
include
int main() { char operator; double num1, num2, result;
printf("Enter first numbers: "); scanf("%lf ", &num1 ); printf("Enter an operator (+, -, *, /): "); scanf(" %c", &operator); printf("Enter second numbers: "); scanf("%lf ", &num2 ); switch (operator) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': if (num2 != 0) { result = num1 / num2; } else { printf("Error: Division by zero is undefined.\n"); return 1; } break; default: printf("Error: Invalid operator.\n"); return 1; } printf("Result: %lf\n", result); return 0;
}
include
int main() { char operator; double num1, num2, result;
}