Odstranit program.c
This commit is contained in:
parent
1b08a156a4
commit
13f41f9ec9
61
program.c
61
program.c
@ -1,61 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define SIZE 256
|
|
||||||
#define MAX 1000
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
char line[SIZE];
|
|
||||||
char *end;
|
|
||||||
|
|
||||||
double x;
|
|
||||||
double pole[MAX];
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
/* nacitanie x */
|
|
||||||
if (fgets(line, SIZE, stdin) == NULL) {
|
|
||||||
printf("Chyba: nepodarilo sa nacitat x.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
x = strtod(line, &end);
|
|
||||||
|
|
||||||
if (end == line) {
|
|
||||||
printf("Chyba: nepodarilo sa nacitat x.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* nacitanie koeficientov */
|
|
||||||
while (fgets(line, SIZE, stdin) != NULL) {
|
|
||||||
|
|
||||||
if (line[0] == '\n') // prazdny riadok
|
|
||||||
break;
|
|
||||||
|
|
||||||
pole[n] = strtod(line, &end);
|
|
||||||
|
|
||||||
if (end == line) {
|
|
||||||
printf("Chyba: nepodarilo sa nacitat koeficient %d.\n", n);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n == 0) {
|
|
||||||
printf("Chyba: nebol zadany ziadny koeficient.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Horner */
|
|
||||||
double vysledok = pole[0];
|
|
||||||
|
|
||||||
for (int i = 1; i < n; i++) {
|
|
||||||
vysledok = vysledok * x + pole[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%.2f\n", vysledok);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user