pvjc20/du4/program.c

26 lines
801 B
C
Raw Permalink Normal View History

2020-04-01 18:52:14 +00:00
#include <stdio.h>
2020-04-02 14:54:16 +00:00
int main(){
2020-04-02 18:08:51 +00:00
while(1){
char read[1000000];
scanf("%[^\n]", read);
2020-04-02 18:11:20 +00:00
scanf("%*c");
2020-04-02 18:08:51 +00:00
float num1, num2, answer;
char action;
sscanf(read, "%f %c %f %*c %f", &num1, &action, &num2, &answer);
if(action != '/' && action != '*' && action != '-' && action != '+'){
printf("CHYBA\n");
return 0;
}
float check = (action == '/') ? num1 / num2 : (action == '*') ? num1 * num2 : (action == '+') ? num1 + num2 : num1 - num2;
check *= 100000;
int tmp = check;
check = (float) tmp / 100000;
answer *= 100000;
tmp = answer;
answer = (float) tmp / 100000;
printf("%s\n", (check == answer) ? "OK" : "ZLE");
//printf("%f\n", check);
2020-04-02 14:54:16 +00:00
}
2020-04-01 18:52:14 +00:00
}