2020-03-20 08:46:43 +00:00
|
|
|
#include<stdlib.h>
|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
long double power(long double x, int y);
|
|
|
|
|
|
|
|
int main() {
|
2020-03-20 09:44:39 +00:00
|
|
|
float x;
|
|
|
|
float coef[100];
|
2020-03-20 08:46:43 +00:00
|
|
|
int coefCount = 0;
|
|
|
|
int retVal;
|
|
|
|
long double result = 0;
|
|
|
|
|
2020-03-20 09:44:39 +00:00
|
|
|
if ((retVal = scanf("%f", &x)) <= 0 || retVal == EOF) {
|
2020-03-20 08:46:43 +00:00
|
|
|
printf("%s\n", "Chyba: Nespravny vstup");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<100; i++) {
|
2020-03-20 09:44:39 +00:00
|
|
|
retVal = scanf("%f", &coef[coefCount]);
|
2020-03-20 08:46:43 +00:00
|
|
|
|
2020-03-20 09:46:52 +00:00
|
|
|
// if (coef[i] == 0) {
|
|
|
|
// break;
|
|
|
|
// }
|
2020-03-20 08:46:43 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|