pvjc20/du4/program.c

56 lines
1.1 KiB
C
Raw Normal View History

2020-03-31 10:25:27 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
2020-03-31 18:40:15 +00:00
int call(long double A, long double B, long double C, char AC){
if(AC=='/'&&B==0 || AC==('+'||'-'||'*'||'-')){
2020-03-31 11:30:05 +00:00
return printf("CHYBA\n");
2020-03-31 10:25:27 +00:00
}
2020-03-31 11:02:27 +00:00
else if(AC=='+'){
2020-03-31 11:11:50 +00:00
if(A+B==C)return printf("OK\n");
return printf("ZLE\n");
2020-03-31 10:25:27 +00:00
}
2020-03-31 18:40:15 +00:00
if(AC=='-'){
2020-03-31 11:11:50 +00:00
if(A-B==C)return printf("OK\n");
return printf("ZLE\n");
2020-03-31 10:25:27 +00:00
}
2020-03-31 18:40:15 +00:00
if(AC=='*'){
2020-03-31 11:11:50 +00:00
if(A*B==C)return printf("OK\n");
return printf("ZLE\n");
2020-03-31 10:25:27 +00:00
}
2020-03-31 11:54:11 +00:00
if(AC=='/'){
2020-03-31 18:40:15 +00:00
long double Cc=A/B;
2020-03-31 11:54:11 +00:00
Cc=(int)(Cc*100000);
Cc=(float)Cc/100000;
2020-03-31 18:40:15 +00:00
if(Cc==C || A/B==C)return printf("OK\n");
// printf("%Lf",Cc);
2020-03-31 11:55:25 +00:00
return printf("ZLE\n");
2020-03-31 11:30:05 +00:00
}
2020-03-31 18:40:15 +00:00
return printf("CHYBA\n");
2020-03-31 10:25:27 +00:00
}
2020-03-31 18:40:15 +00:00
2020-03-31 10:25:27 +00:00
int main()
{
char *str;
str=(char*)malloc(100);
2020-03-31 18:40:15 +00:00
long double a,b,c;
2020-03-31 11:02:27 +00:00
char ac,el;
int ind=0;
for(int i=0;el!='\n';i++){
el=getchar();
if(isspace(el)){
continue;
}
str[ind]=el;
ind++;
}
2020-03-31 18:40:15 +00:00
//3␣/␣45␣=␣0.06666↵
//scanf("%s",str);
sscanf(str,"%Lf%c%Lf=%Lf ",&a,&ac,&b,&c);
//printf("\n%f %c %f =%f ",a,ac,b,c);
2020-03-31 10:25:27 +00:00
call(a,b,c,ac);
return 0;
2020-03-31 11:09:47 +00:00
}
2020-03-31 18:40:15 +00:00