From eb4dee21c42baf71cde64f3c0200f7032dd41a3b Mon Sep 17 00:00:00 2001 From: Pavlo Tverdyi Date: Tue, 31 Mar 2020 11:02:27 +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 | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/du4/program.c b/du4/program.c index d5860cd..a721101 100644 --- a/du4/program.c +++ b/du4/program.c @@ -7,19 +7,19 @@ int call(double A, double B, double C, char AC){ if(AC=='/'&&B==0){ return printf("CHYBA");; } - if(AC=='+'){ + else if(AC=='+'){ if(A+B==C)return printf("OK"); return printf("ZLE"); } - if(AC=='-'){ + else if(AC=='-'){ if(A-B==C)return printf("OK"); return printf("ZLE"); } - if(AC=='*'){ + else if(AC=='*'){ if(A*B==C)return printf("OK"); return printf("ZLE"); } - if(AC=='/'){ + else if(AC=='/'){ if(A/B==C)return printf("OK"); return printf("ZLE"); } @@ -31,12 +31,20 @@ int main() char *str; str=(char*)malloc(100); -double a=1,b,c; -char ac; -scanf("%s",str); -sscanf(str,"%lf%c%lf=%lf",&a,&ac,&b,&c); -//printf("%d%c%d=%d",a,ac,b,c); -call(a,b,c,ac); -//if(result) - return 0; +double a,b,c; +char ac,el; +int ind=0; +for(int i=0;el!='\n';i++){ + el=getchar(); + if(isspace(el)){ + continue; + } + str[ind]=el; + ind++; } +//scanf("%s",str); +sscanf(str,"%lf%c%lf=%lf ",&a,&ac,&b,&c); +//printf("%f %d %f =%f",a,ac,b,c); +call(a,b,c,ac); + return 0; +} \ No newline at end of file