Изменить 'du4/program.c'

This commit is contained in:
Pavlo Tverdyi 2020-03-31 11:11:50 +00:00
parent 995379371c
commit 647e9e5535

View File

@ -5,30 +5,28 @@
int call(float A, float B, float C, char AC){ int call(float A, float B, float C, char AC){
if(AC=='/'&&B==0){ if(AC=='/'&&B==0){
return printf("CHYBA");; return printf("CHYBA\n");;
} }
else if(AC=='+'){ else if(AC=='+'){
if(A+B==C)return printf("OK"); if(A+B==C)return printf("OK\n");
return printf("ZLE"); return printf("ZLE\n");
} }
else if(AC=='-'){ else if(AC=='-'){
if(A-B==C)return printf("OK"); if(A-B==C)return printf("OK\n");
return printf("ZLE"); return printf("ZLE\n");
} }
else if(AC=='*'){ else if(AC=='*'){
if(A*B==C)return printf("OK"); if(A*B==C)return printf("OK\n");
return printf("ZLE"); return printf("ZLE\n");
} }
else if(AC=='/'){ else if(AC=='/'){
if(A/B==C)return printf("OK"); if(A/B==C)return printf("OK\n");
return printf("ZLE"); return printf("ZLE\n");
} }
} }
int main() int main()
{ {
char *str; char *str;
str=(char*)malloc(100); str=(char*)malloc(100);
float a,b,c; float a,b,c;
@ -42,10 +40,7 @@ for(int i=0;el!='\n';i++){
str[ind]=el; str[ind]=el;
ind++; ind++;
} }
//3.4␣+␣2.3␣=␣5.7␣
//scanf("%s",str);
sscanf(str,"%f%c%f=%f ",&a,&ac,&b,&c); sscanf(str,"%f%c%f=%f ",&a,&ac,&b,&c);
//printf("%f %c %f =%f",a,ac,b,c);
call(a,b,c,ac); call(a,b,c,ac);
return 0; return 0;
} }