pvjc20/du4/program.c

52 lines
946 B
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 11:09:47 +00:00
int call(float A, float B, float C, char AC){
2020-03-31 10:25:27 +00:00
if(AC=='/'&&B==0){
2020-03-31 11:09:47 +00:00
return printf("CHYBA");;
2020-03-31 10:25:27 +00:00
}
2020-03-31 11:02:27 +00:00
else if(AC=='+'){
2020-03-31 11:09:47 +00:00
if(A+B==C)return printf("OK");
return printf("ZLE");
2020-03-31 10:25:27 +00:00
}
2020-03-31 11:02:27 +00:00
else if(AC=='-'){
2020-03-31 11:09:47 +00:00
if(A-B==C)return printf("OK");
return printf("ZLE");
2020-03-31 10:25:27 +00:00
}
2020-03-31 11:02:27 +00:00
else if(AC=='*'){
2020-03-31 11:09:47 +00:00
if(A*B==C)return printf("OK");
return printf("ZLE");
2020-03-31 10:25:27 +00:00
}
2020-03-31 11:02:27 +00:00
else if(AC=='/'){
2020-03-31 11:09:47 +00:00
if(A/B==C)return printf("OK");
return printf("ZLE");
2020-03-31 10:25:27 +00:00
}
}
int main()
{
char *str;
str=(char*)malloc(100);
2020-03-31 11:09:47 +00:00
float 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 11:09:47 +00:00
//3.4␣+␣2.3␣=␣5.7␣
2020-03-31 11:02:27 +00:00
//scanf("%s",str);
2020-03-31 11:09:47 +00:00
sscanf(str,"%f%c%f=%f ",&a,&ac,&b,&c);
2020-03-31 11:10:35 +00:00
//printf("%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
}