From f8e6bfcd6aa028dd33a58030396b7ea870f9d1a4 Mon Sep 17 00:00:00 2001 From: Igor Dzuro Date: Fri, 20 Mar 2020 09:22:15 +0100 Subject: [PATCH] fix --- a1/program.c | 78 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/a1/program.c b/a1/program.c index 42a3d83..07f6041 100644 --- a/a1/program.c +++ b/a1/program.c @@ -1,15 +1,65 @@ -#include +#include +#include -int main(){ -double x ; -double a ; -double b ; -double c ; -scanf("%lf",&x); -scanf("%lf",&a); -scanf("%lf",&b); -scanf("%lf",&c); -double r = (a*(x*x))+(b*x)+c; -printf ("Vysledok je :%.2lf\n",r); - -} \ No newline at end of file +long double power(long double x, int y); + +int main() { + double x; + double coef[100]; + int coefCount = 0; + int retVal; + long double result = 0; + + if ((retVal = scanf("%lf", &x)) <= 0 || retVal == EOF) { + printf("%s\n", "Chyba: Nespravny vstup"); + return 0; + } + + for (int i=0; i<100; i++) { + retVal = scanf("%lf", &coef[coefCount]); + + if (coef[i] == 0) { + break; + } + + if (retVal <= 0 || retVal == EOF) { + break; + } + + coefCount++; + } + + // printf("CoefCount:%d\n", coefCount); + + for (int i=0; i 0) { + result += coef[i] * power(x, pCoef); + } else { + result += coef[i]; + } + + // printf("c:%lf; p:%d; r:%Lf\n", coef[i], pCoef, result); + } + + printf("Vysledok je :%.2Lf\n", result); + + return 0; +} + +long double power(long double x, int y) { + long double result = x; + + if (y == 0) { + return 0; + } else if (y == 1) { + return result; + } + + for (int i=0; i