From ad0de7177ac235d970e8aea66a25e3411a0cd816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Korpesio?= Date: Tue, 19 Oct 2021 19:45:32 +0200 Subject: [PATCH] prvy --- cv3/program.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 cv3/program.c diff --git a/cv3/program.c b/cv3/program.c new file mode 100644 index 0000000..b991043 --- /dev/null +++ b/cv3/program.c @@ -0,0 +1,62 @@ +#include +#include +#include + +#define LINESIZE 100 + +struct kalkulacka{ + float cislo; }; + +int main() { + struct kalkulacka number[LINESIZE]; + memset(number, 0, sizeof(struct kalkulacka) * LINESIZE); + char line[LINESIZE]; + size_t velkost; + memset(line, 0, LINESIZE); + int a = 0; + int i; + int input = 0; + float p; + //float prvy, druhy, vys; + while (fgets(line, LINESIZE, stdin)) { + velkost = strlen(line); + if (velkost == 1 && line[velkost - 1] == '\n') { + break; + } + if (input >= 10){ + printf("no input"); + break; + } + if (line[0] == '+' || line[0] == '-' || line[0] == '*' || line[0] == '/') { + input =+ 2; + if (line[0] == '+') { + number[a - 2].cislo = number[a - 2].cislo + number[a - 1].cislo; + a--; + } + if (line[0] == '-') { + number[a - 2].cislo = number[a - 2].cislo - number[a - 1].cislo; + a--; + } + if (line[0] == '*') { + number[a - 2].cislo = number[a - 2].cislo * number[a - 1].cislo; + a--; + } + if (line[0] == '/') { + number[a - 2].cislo = number[a - 2].cislo / number[a - 1].cislo; + a--; + } + } + else { + p = atof(line); + number[a].cislo = p; + a++; + input++; + } + + for (i = 0; i < a; i++){ + printf("%f ", number[i].cislo); + } + printf("\n"); + } + return 0; +} \ No newline at end of file