Aktualizovat „du4/program.c“

This commit is contained in:
Bohdan Yanchyk 2020-04-02 23:29:32 +00:00
parent 2db9765b0e
commit ce16210809

View File

@ -59,27 +59,30 @@ double compare_percent(double a, double b, double eps)
int main() int main()
{ {
char str[100]; char str[100][100];
memset(str,0,100); int i =0;
fgets(str,100,stdin); for(;i<100;i++){
char *new_str = compactString(str,strlen(str)); scanf("%s",str[i]);
double first =-5,second =-5,res=-5;
char c='E';
sscanf(new_str,"%lf%c%lf%*[=]%lf",&first,&c,&second,&res);
if(c=='E'||first==-5||second==-5||res==-5||(c!=43&&c!=42&&c!=45&&c!=47)){
printf("CHYBA\n");
return 0;
}
double my_res = operation(first,second,c);
if(compare_percent(res,my_res,0.01)==0){
printf("OK\n");
}
else{
printf("ZLE\n");
} }
for(int k=0;k<i;k++){
char *new_str = compactString(str,strlen(str));
double first =-5,second =-5,res=-5;
char c='E';
sscanf(new_str,"%lf%c%lf%*[=]%lf",&first,&c,&second,&res);
if(c=='E'||first==-5||second==-5||res==-5||(c!=43&&c!=42&&c!=45&&c!=47)){
printf("CHYBA\n");
return 0;
}
double my_res = operation(first,second,c);
if(compare_percent(res,my_res,0.01)==0){
printf("OK\n");
}
else{
printf("ZLE\n");
}
}
return 0; return 0;
} }