This commit is contained in:
Igor Dzuro 2020-03-20 09:22:15 +01:00
parent cc6d3354bc
commit f8e6bfcd6a

View File

@ -1,15 +1,65 @@
#include <stdio.h> #include<stdlib.h>
#include<stdio.h>
int main(){ long double power(long double x, int y);
double x ;
double a ; int main() {
double b ; double x;
double c ; double coef[100];
scanf("%lf",&x); int coefCount = 0;
scanf("%lf",&a); int retVal;
scanf("%lf",&b); long double result = 0;
scanf("%lf",&c);
double r = (a*(x*x))+(b*x)+c; if ((retVal = scanf("%lf", &x)) <= 0 || retVal == EOF) {
printf ("Vysledok je :%.2lf\n",r); 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<coefCount; i++) {
int pCoef = coefCount - i - 1;
if (pCoef > 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<y-1; i++) {
result *= x;
}
return result;
}