pvjc20/du4/program.c

51 lines
1022 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||AC==('+'||'-'||'*'||'-')){
return printf("CHYBA\n");
}
else if(AC=='+'){
if(A+B==C)return printf("OK\n");
return printf("ZLE\n");
}
else if(AC=='-'){
if(A-B==C)return printf("OK\n");
return printf("ZLE\n");
}
else if(AC=='*'){
if(A*B==C)return printf("OK\n");
return printf("ZLE\n");
}
if(AC=='/'){
float Cc=A/B;
Cc=(int)(Cc*100000);
Cc=(float)Cc/100000;
if(Cc==C)return printf("OK/n");
printf("%f",Cc);
return printf("ZLE/n");
}
return printf("CHYBA");
}
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++;
}
sscanf(str,"%f%c%f=%f ",&a,&ac,&b,&c);
call(a,b,c,ac);
return 0;
}