Aktualizovat „du4/program.c“

This commit is contained in:
Artem Horbunov 2020-04-02 18:08:51 +00:00
parent 62bef9862b
commit ab77dc0676

View File

@ -1,22 +1,24 @@
#include <stdio.h> #include <stdio.h>
int main(){ int main(){
char read[1000000]; while(1){
scanf("%[^\n]", read); char read[1000000];
float num1, num2, answer; scanf("%[^\n]", read);
char action; float num1, num2, answer;
sscanf(read, "%f %c %f %*c %f", &num1, &action, &num2, &answer); char action;
if(action != '/' && action != '*' && action != '-' && action != '+'){ sscanf(read, "%f %c %f %*c %f", &num1, &action, &num2, &answer);
printf("CHYBA\n"); if(action != '/' && action != '*' && action != '-' && action != '+'){
return 0; 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);
} }
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);
} }