pvjc24/cv3/program.c

52 lines
1.2 KiB
C
Raw Permalink Normal View History

2024-03-06 14:21:26 +00:00
#include <stdio.h>
int main() {
float array[50];
int repetitions = 0;
float number = 0;
char line[100];
int valid = 1;
2024-03-06 14:26:52 +00:00
//tu sa hlada x
2024-03-06 14:21:26 +00:00
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");
2024-03-06 14:24:33 +00:00
return 0;
2024-03-06 14:21:26 +00:00
}
} else {
printf("Nepodarilo sa nacitat x\n");
2024-03-06 14:24:33 +00:00
return 0;
2024-03-06 14:21:26 +00:00
}
// 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);
2024-03-06 14:24:33 +00:00
return 0;
2024-03-06 14:21:26 +00:00
}
} 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;
}