From 1c8b217cb3d173ae49604dbd30e8bb1490cbcab0 Mon Sep 17 00:00:00 2001 From: Pavlo Tverdyi Date: Wed, 1 Apr 2020 09:33:19 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20'du4/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du4/program.c | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) 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; } +