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