pvjc20/du4/program.c

17 lines
509 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");
return -1;
}
2020-04-02 15:54:39 +00:00
float check = (action == '/') ? num1 / num2 : (action == '*') ? num1 * num2 : (action == '+') ? num1 + num2 : num1 - num2;
2020-04-02 14:54:16 +00:00
printf("%s\n", (check == answer) ? "OK" : "ZLE");
2020-04-02 15:43:58 +00:00
2020-04-01 18:52:14 +00:00
}