From 7ba9b3ef0b86be5ffd2f5098ac050d737f98a8fe Mon Sep 17 00:00:00 2001 From: Patrik Seman Date: Thu, 16 Mar 2023 15:43:09 +0100 Subject: [PATCH] program.c --- du4/program.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 du4/program.c diff --git a/du4/program.c b/du4/program.c new file mode 100644 index 0000000..a1dda95 --- /dev/null +++ b/du4/program.c @@ -0,0 +1,64 @@ +#include +#include + + +int main(){ + + char vstup[100]; + float x; + float y; + float z; + char znamienko; + + while(fgets(vstup, 100, stdin)==NULL || *vstup=='\n'){ + if(sscanf(vstup, "%f %c %f = %f", &x, znamienko ,&y ,&z)!=4){ + printf("CHYBA\n"); + continue; + } + if(znamienko == '+'){ + float rozdiel; + rozdiel=(x+y)-z; + if(rozdiel>-0.001 && rozdiel<0.001){ + printf("OK\n"); + } + else{ + printf("ZLE\n"); + } + } + else if(znamienko == '-'){ + float rozdiel; + rozdiel=(x-y)-z; + if(rozdiel>-0.001 && rozdiel<0.001){ + printf("OK\n"); + } + else{ + printf("ZLE\n"); + } + } + else if(znamienko == '*'){ + float rozdiel; + rozdiel=(x*y)-z; + if(rozdiel>-0.001 && rozdiel<0.001){ + printf("OK\n"); + } + else{ + printf("ZLE\n"); + } + } + else if(znamienko == '/'){ + float rozdiel; + rozdiel=(x/y)-z; + if(rozdiel>-0.001 && rozdiel<0.001){ + printf("OK\n"); + } + else{ + printf("ZLE\n"); + } + } + else{ + printf("CHYBA\n"); + } + + } + +} \ No newline at end of file