pvjc20/du4/program.c

48 lines
951 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char add(double A, double B, double C,char AC){
if(A+B==C)return printf("OK\n");
return printf("ZLE\n");
}
char subtr(double A, double B, double C,char AC){
if(A-B==C)return printf("OK\n");
return printf("ZLE\n");
}
char multi(double A, double B, double C,char AC){
if(A*B==C)return printf("OK\n");
return printf("ZLE\n");
}
char divi(double A, double B, double C,char AC){
float CC=A/B;
if(CC==C || A/B==C)return printf("OK\n");
return printf("ZLE\n");
}
int main()
{
char *str;
str=(char*)malloc(100);
double a,b,c;
char ac,el;
int ind=0;
for(int i=0;el!='\n';i++){
el=getchar();
if(isspace(el)){
continue;
}
str[ind]=el;
ind++;
}
sscanf(str,"%lF%c%lF=%lF ",&a,&ac,&b,&c);
if(ac=='+')add(a,b,c,ac);
if(ac=='-')subtr(a,b,c,ac);
if(ac=='*')multi(a,b,c,ac);
if(ac=='/')divi(a,b,c,ac);
return 0;
}