prvcj22/du4/program.c

77 lines
1.3 KiB
C

#include<stdio.h>
#include<math.h>
struct try
{
double number1;
char sign;
double number2;
double final;
};
void ok();
void zle();
int main(){
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;
}
}
}
return 0;
}
void ok(){
printf("OK\n");
}
void zle(){
printf("ZLE\n");
}