From 3637255a095704beea6957335b9290bb396f7ad0 Mon Sep 17 00:00:00 2001 From: Weber Date: Thu, 28 Mar 2024 17:47:51 +0000 Subject: [PATCH] test --- a1/program.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/a1/program.c b/a1/program.c index e69de29..a18dcf3 100644 --- a/a1/program.c +++ b/a1/program.c @@ -0,0 +1,54 @@ +#include +#include +#include + +#define MAX_LINE_LENGTH 100 + +int main() { + char uloha[MAX_LINE_LENGTH]; + + while (fgets(uloha, MAX_LINE_LENGTH, stdin) != NULL) { + + int cislo1, cislo2, vysledok_zadany; + char operacia; + + + if (sscanf(uloha, "%d %c %d = %d", &cislo1, &operacia, &cislo2, &vysledok_zadany) != 4) { + printf("CHYBA\n"); + continue; + } + + double vysledok_skutocny; + + + switch (operacia) { + case '+': + vysledok_skutocny = cislo1 + cislo2; + break; + case '-': + vysledok_skutocny = cislo1 - cislo2; + break; + case '*': + vysledok_skutocny = cislo1 * cislo2; + break; + case '/': + if (cislo2 == 0) { + printf("CHYBA\n"); + continue; + } + vysledok_skutocny = (double)cislo1 / cislo2; + break; + default: + printf("CHYBA\n"); + continue; + } + + if (fabs(vysledok_skutocny - round(vysledok_skutocny * 100) / 100.0) < 1e-6 && vysledok_zadany == round(vysledok_skutocny * 100) / 100.0) { + printf("OK\n"); + } else { + printf("ZLE\n"); + } + } + + return 0; +} \ No newline at end of file