From 3db3c1b9005bffb68179f00c8c16b6c5ef983be0 Mon Sep 17 00:00:00 2001 From: Peter Sabol Date: Thu, 31 Mar 2022 10:24:10 +0200 Subject: [PATCH] funguje --- du4/program | Bin 7996 -> 7960 bytes du4/program.c | 124 +++++++++++++++++++------------------------------- 2 files changed, 48 insertions(+), 76 deletions(-) diff --git a/du4/program b/du4/program index e5fc2da53157021050cef68ee4be71856ade840e..b2407204a842eb253fad2763162f4fefc8feff74 100755 GIT binary patch delta 2963 zcmai04N#Ot7~b#r?)VPQ`|h~o=Md*kIY1N?%s&QGFj5*YQSt|+)JnrLwF$K!$Aj)r zNl9?6(S{sNo5{+gV2a9SXih~(o2W@sn=_oDI@HFWM#4hBp7*{xxp5f%X5M@E*?0Hd zXP@2M-NTc2POeYT@2L@`v5c|J4MU&N`enxa4Yh-{g#u$G4F_gMG1RbaqQtgwjj%T5 z?Qs(ltGDlrpHQd#+-~DOlWzCw2(&Q6qG3i@6#r4M%%EB%VIoWmi-ehAlur+nUQgnGIpCPgb2LSKho;4R>Mc>CjArC&fG^}_5x>SyFMe$5Ba6n2dWeNe zS=5b}iaDtrDA2g3<;yXYhMlJfKCwZRbQrV{UTfl?i&G{?F*X(`5)+w79_=TQ$D~T# zS0uj-Ue(^|V7pq=jCdt38^S{nt~q7u{XgN}iZq(FCp)dH9(% zx1w<)AE8SdUxaj-G@`p#w@&l7x0RS6&CNNrzq_v_w2Mv(Djg@h^>vl0td&q^A>X7+ zPYVQoqCiV3^{RTf7(uqi66h-V*Mrb8Z885vSK#WyptT++Wp6KViX`bcV|Nq< zp;M^3EY$C%thEJBiJDP-iyEp$>!kjc?!$o&O!hdijA|#exO7`lf*s^9*rX`gBOtuR z;|R2-Dn<5Og~t7jJZ-Yar{iBn=1ZTUH<+|+mqrU;^DL>rI1V*AUfI15g#8t$O5=z0 zI(|qRE9iKa^ltP>sGj3}d71y|KAtV5B059x@!R?|&C&mY6*@jUYE4QDrYCQmihP(P z*dGCos5C=_4oKtQ_phRK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|4Hn0$D_o~V&1YlX4=a6!~^68@}Cf3b5ek+M1UaLxIXUQ?}_dclH6ZNxWjuy++OYnFIcmX=)cl$5Sm zzK7SrkhtJ*pcSAGXpeQc{4-M2(G^<`-Lz$CWVQ9ZjMt(G1hd$! z%a;IC2?&>-aBMUvd_()GuWf+K^CoUc)`oCng8P8^9&e@BY;NCT%p4$oFPxx;utDK@ z9XP)yeD`L6crhfi$`3ipTgB_$1fLA7C1_10#cs))g~iK2YeAbpJ3t3PM?fb*=Rv=N zZh?%O>POihNYZv1nc+5aq8=SB&FE?79DUd;4^?Nl&764&F0oen42V~pj8=K6CBrRq zK7NuM*)nHbM|~aHX0D+D7K>@7!)@elIAmJy=xH8<=@|5)ncjD}Q~1%fp(7;^8<8-ZUE9xu-G8f4?+(x$~dW2wITomVLNpeY7DnTjmS5 z2s0-&W!j`7`Ytm^3e%m;9JvH-ZKht%Y-4^m^ifZfon=9;6&)1%*psPkiiUZMw9V2m z-Z%^{TEj6WxNHq;k2)8xVeN_L7HF8CZS6>Cm=B1UF1Qt%Kzqx%85-s<1)Lp}s$u?$ z5Q2N6VLlPs=ZJ>+wBUx{Mw_x$+PNW`*cB5Ok?a~hs5l;6C(=Y7q9sY6&RN~6w|Cno>G3^RU)S9) F{R{H!+1~&F diff --git a/du4/program.c b/du4/program.c index cfb85f3..474081f 100644 --- a/du4/program.c +++ b/du4/program.c @@ -5,12 +5,14 @@ #include -int main() { - int i,j; + +int main(){ + + int i,j; double number1, number2, summary,msum; char operand, equ; float rsum=0; - /* char input[1000]; +/* char input[1000]; char num_str[30] = {0}; float numbers[3]; fgets(input, 999, stdin); @@ -37,7 +39,7 @@ int main() { */ char* input = calloc(1000, 1); while (1) { - + input = fgets(input, 1000, stdin); if (input == NULL) break; @@ -45,9 +47,9 @@ int main() { if (input[0] == '\n' || input[0] == EOF || strlen(input) <= 0) break; - float values[3] = {0}; + float values[3] = {0}; char operation = 0; - + int k = 0; int num = strlen(input); for (int i = 0; i < num; i++) { @@ -58,7 +60,7 @@ int main() { if (isalpha(input[i])) break; - + if (i < strlen(input) && (isdigit(input[i]) || input[i] == '.' || (input[i] == '-' && isdigit(input[i + 1])))) { char temp[100] = {0}; for (int j = 0; i < strlen(input) && (isdigit(input[i]) || input[i] == '.' || input[i] == '-'); j++) { @@ -73,54 +75,26 @@ int main() { } } - + if (k != 3) { printf("CHYBA\n"); continue; } + if (operation == 0 && values[1] < 0) { operation = '-'; values[1] = abs(values[1]); } - - float result = 0; - - switch (operation) { - case '+': { - result = values[0] + values[1]; - break; - } - case '-': { - result = values[0] - values[1]; - break; - } - case '/': { - result = values[0] / values[1]; - break; - } - case '*': { - result = values[0] * values[1]; - break; - } - default: { - printf("CHYBA\n"); - continue; - } - } - - - char result_string[50]; - sprintf(result_string, "%.2f", result); - result = atof(result_string); - - if (result == values[2]) - printf("OK\n"); - else - printf("ZLE\n"); - } - if((operand == '/') && (number2 == 0)){ + + float result = 0; + + + +//////////////////////////////////////////////// + + if((operand == '/') && (number2 == 0)){ printf("Nulou sa nedá deliť"); } if(operand !='+' && operand !='-' && operand !='*' && operand !='/'){ @@ -128,22 +102,35 @@ int main() { printf("\n"); } - //msum=values[2]; - if(operand=='+'){ - // rsum=values[0]+values[1]; + msum=values[2]; + if(operation=='+'){ + rsum=values[0]+values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); if(msum==rsum){ - //printf("OK\n"); + printf("OK\n"); } else{ - //printf("ZLE\n"); + printf("ZLE\n"); } - //printf("%lf\n",rsum); + printf("%lf\n",rsum); } - else if(operand=='-'){ - // rsum=values[0]-values[1]; + else if(operation=='-'){ + rsum=values[0]-values[1]; + char rmsum[50]; + sprintf(rmsum, "%.2f", msum); + msum = atof(rmsum); + if(msum==rsum){ + printf("OK\n"); + } + else{ + printf("ZLE\n"); + } + printf("%lf\n",rsum); + } + else if(operation=='*'){ + rsum=values[0]*values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); @@ -151,37 +138,22 @@ int main() { //printf("OK\n"); } else{ - //printf("ZLE\n"); + printf("ZLE\n"); } - //printf("%lf\n",rsum); + printf("%lf\n",rsum); } - else if(operand=='*'){ - // rsum=values[0]*values[1]; + else if(operation=='/'){ + rsum=values[0]/values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); if(msum==rsum){ - //printf("OK\n"); + printf("OK\n"); } else{ - //printf("ZLE\n"); + printf("ZLE\n"); } - //printf("%lf\n",rsum); + printf("%lf\n",rsum); } - else if(operand=='/'){ - // rsum=values[0]/values[1]; - char rmsum[50]; - sprintf(rmsum, "%.2f", msum); - msum = atof(rmsum); - if(msum==rsum){ - //printf("OK\n"); - } - else{ - //printf("ZLE\n"); - } - //printf("%lf\n",rsum); } - free(input); - - return 0; -} + } \ No newline at end of file