This commit is contained in:
Weber 2024-03-06 14:21:26 +00:00
parent f56738976e
commit 12d2e76858

View File

@ -0,0 +1,51 @@
#include <stdio.h>
int main() {
float array[50];
int repetitions = 0;
float number = 0;
char line[100];
int valid = 1;
//tu sa halda x
if (fgets(line, sizeof(line), stdin) != NULL) {
if (sscanf(line, "%f", &number) == 1) {
array[repetitions] = number;
repetitions++;
} else {
printf("Nepodarilo sa nacitat zaklad x\n");
return 1;
}
} else {
printf("Nepodarilo sa nacitat x\n");
return 1;
}
// tu sa halda koeficient
while (repetitions < 50) {
if (fgets(line, sizeof(line), stdin) != NULL) {
if (line[0] == '\n') {
break;
}
if (sscanf(line, "%f", &number) == 1) {
array[repetitions] = number;
repetitions++;
} else {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", repetitions);
return 1;
}
} else {
break;
}
}
//pocty
float result = array[1];
for (int i = 2; i < repetitions; ++i) {
result = result * array[0] + array[i];
}
printf("Vysledok je: %.2f\n", result);
return 0;
}