diff --git a/du4/program b/du4/program new file mode 100644 index 0000000..bd51f49 Binary files /dev/null and b/du4/program differ diff --git a/du4/program.c b/du4/program.c new file mode 100644 index 0000000..dcba597 --- /dev/null +++ b/du4/program.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include + +struct priklad//vytvorenie štruktúry, typu, v ktorom existujú iné typy +{ + double one; + char znak; + double two; + double sum; +}; + +int sort(struct priklad prik[20]); +void printAll(struct priklad prik[20], int i); + +int main(){ + +struct priklad prik[20]; +int i = sort(prik); + +printAll(prik,i); + + return 0; +} +void printAll(struct priklad prik[20], int i){ + for (size_t j = 0; j < i; j++) +{ +if( prik[j].one == 0 && prik[j].two == 0 &&prik[j].sum == 0){ + printf("CHYBA\n"); + continue; +} + if(prik[j].znak == '+'){ + // printf("%f", prik[j].one + prik[j].two); + if (round((prik[j].one + prik[j].two)*100)/100 == prik[j].sum)// round-zaokrúhli číslo + { + printf("OK\n"); + } else + { + printf("ZLE\n"); + } + + } + if(prik[j].znak == '-'){ + if (round((prik[j].one - prik[j].two)*100)/100 == prik[j].sum) + { + printf("OK\n"); + } else + { + printf("ZLE\n"); + } + + } + if(prik[j].znak == '*'){ + if (round(prik[j].one * prik[j].two * 100) / 100 == prik[j].sum) + { + printf("OK\n"); + } else + { + printf("ZLE\n"); + } + + } + if(prik[j].znak == '/'){ + if (round(prik[j].one / prik[j].two * 100) / 100 == prik[j].sum) + { + printf("OK\n"); + } else + { + printf("ZLE\n"); + } + + } + +} +} + +int sort(struct priklad prik[20]){ +int i = 0; + while (1) + { + char step_line[30]; + char step_one[5]; + memset(step_one,' ',5);//vyplnenie štandardnými hodnotami poľa + char step_two[10]; + memset(step_two,' ',10); + char step_sum[10]; + memset(step_sum,' ',10); + char* r = fgets(step_line,30,stdin); //číta koncový znak + if (r == NULL){ + break; + } + int k = 0; + while (step_line[k] != ' ') + { + step_one[k] = step_line[k]; + k++; + } + k++; + prik[i].znak = step_line[k]; + k = k+2; + int j = 0; + while (step_line[k]!= ' ') + { + step_two[j] = step_line[k]; + k++; + j++; + } + + + k = k+3; + int p = 0; + while (k