pvjc20/du4/program.c

23 lines
687 B
C
Raw Normal View History

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