prvcj22/du4/program.c

77 lines
1.3 KiB
C
Raw Normal View History

2022-03-31 08:08:20 +00:00
#include<stdio.h>
#include<math.h>
struct try
{
double number1;
char sign;
double number2;
double final;
};
void ok();
void zle();
2022-03-30 13:13:54 +00:00
int main(){
2022-03-31 08:08:20 +00:00
struct try y1[20];
int idx =0;
while (5){
int r = scanf("%lf", &y1[idx].number1);
if (r == -1){
break;
}
scanf(" %c ", &y1[idx].sign);
scanf("%lf", &y1[idx].number2);
scanf(" = %lf",&y1[idx].final);
idx=idx+1;
}
int nikita=0;
while (nikita < idx){
idx=idx+1;
if(y1[nikita].sign == '+'){
if (round((y1[nikita].number1 + y1[nikita].number2)*100)/100 == y1[nikita].final)
{
ok();
break;
} else{
zle();
break;
}
}
if(y1[nikita].sign == '-'){
if (round((y1[nikita].number1 - y1[nikita].number2)*100)/100 == y1[nikita].final){
ok();
break;
} else{
zle();
break;
}
}
if(y1[nikita].sign == '*'){
if (round(y1[nikita].number1 * y1[nikita].number2 * 100) / 100 == y1[nikita].final)
{
ok();
break;
} else
{
zle();
break;
}
}
if(y1[nikita].sign == '/'){
if (round(y1[nikita].number1 / y1[nikita].number2 * 100) / 100 == y1[nikita].final)
{
ok();
break;
} else{
zle();
break;
}
}
2022-03-30 13:13:54 +00:00
}
2022-03-31 08:08:20 +00:00
return 0;
2022-03-30 13:13:54 +00:00
}
2022-03-31 08:08:20 +00:00
void ok(){
2022-03-30 13:13:54 +00:00
printf("OK\n");
}
2022-03-31 08:08:20 +00:00
void zle(){
printf("ZLE\n");
2022-03-30 13:13:54 +00:00
}