pvjc20/du4/program.c

52 lines
944 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int call(float A, float B, float C, char AC){
if(AC=='/'&&B==0){
return printf("CHYBA");;
}
else if(AC=='+'){
if(A+B==C)return printf("OK");
return printf("ZLE");
}
else if(AC=='-'){
if(A-B==C)return printf("OK");
return printf("ZLE");
}
else if(AC=='*'){
if(A*B==C)return printf("OK");
return printf("ZLE");
}
else if(AC=='/'){
if(A/B==C)return printf("OK");
return printf("ZLE");
}
}
int main()
{
char *str;
str=(char*)malloc(100);
float 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++;
}
//3.4␣+␣2.3␣=␣5.7␣
//scanf("%s",str);
sscanf(str,"%f%c%f=%f ",&a,&ac,&b,&c);
printf("%f %c %f =%f",a,ac,b,c);
call(a,b,c,ac);
return 0;
}