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

This commit is contained in:
Pavlo Tverdyi 2020-04-01 09:33:19 +00:00
parent 2d291ebe9a
commit 1c8b217cb3

View File

@ -3,28 +3,27 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
int call( double A, double B, double C, char AC){ char add(double A, double B, double C,char AC){
double cC=(double)C; if(A+B==C)return printf("OK\n");
if(AC=='/'&&B==0 || AC==('+'||'-'||'*'||'-')){ printf("%lf",A+B);
return printf("CHYBA\n");
}
else if(AC=='+'){
if(A+B==C || C==cC)return printf("OK\n");
return printf("ZLE\n"); return printf("ZLE\n");
} }
if(AC=='-'){ char subtr(double A, double B, double C,char AC){
if(A-B==C)return printf("OK\n"); if(A-B==C)return printf("OK\n");
printf("%lf",A-B);
return printf("ZLE\n"); return printf("ZLE\n");
} }
if(AC=='*'){ char multi(double A, double B, double C,char AC){
if(A*B==C)return printf("OK\n"); if(A*B==C)return printf("OK\n");
printf("%lf",A*B);
return printf("ZLE\n"); return printf("ZLE\n");
} }
if(AC=='/'){ char divi(double A, double B, double C,char AC){
if(A/B==C || A/B==cC || C==cC)return printf("OK\n"); float CC=A/B;
printf("%f",CC);
if(CC==C || A/B==C)return printf("OK\n");
printf("%lf",A/B);
return printf("ZLE\n"); return printf("ZLE\n");
}
return printf("CHYBA\n");
} }
int main() int main()
@ -42,11 +41,12 @@ for(int i=0;el!='\n';i++){
str[ind]=el; str[ind]=el;
ind++; ind++;
} }
//134.5␣/␣6.7␣=␣20.07462686567164
//scanf("%s",str);
sscanf(str,"%lF%c%lF=%lF ",&a,&ac,&b,&c); sscanf(str,"%lF%c%lF=%lF ",&a,&ac,&b,&c);
//printf("\n%Lf %c %Lf =%Lf ",a,ac,b,c); if(ac=='+')add(a,b,c,ac);
call(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; return 0;
} }