31 lines
881 B
C
31 lines
881 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
#define MAX_LEN 100
|
|
|
|
const char* evaluate_expression(char *expression){
|
|
double num1, num2, result, computed_result;
|
|
char op;
|
|
|
|
if(sscanf(expression, " %lf %c %lf = %lf ", &num1, &op, &num2, &result) != 4) return "CHYBA";
|
|
|
|
switch(op){
|
|
case '+': computed_result = num1 + num2; break;
|
|
case '-': computed_result = num1 - num2; break;
|
|
case '*': computed_result = num1 * num2; break;
|
|
case '/': if (num2 == 0) return "ZLE"; computed_result = num1 / num2; break;
|
|
default: return "CHYBA";
|
|
}
|
|
|
|
return (round(computed_result * 100) / 100 == round(result * 100) / 100) ? "OK" : "ZLE";
|
|
}
|
|
|
|
int main(){
|
|
char line[MAX_LEN];
|
|
while(fgets(line, sizeof(line), stdin) && line[0] != '\n'){
|
|
printf("%s\n", evaluate_expression(line));
|
|
}
|
|
return 0;
|
|
}
|