54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include <ctype.h>
|
|
|
|
#define LINE_SIZE 1024
|
|
|
|
int main() {
|
|
char line[LINE_SIZE];
|
|
char* endptr = NULL;
|
|
char* r = NULL;
|
|
double x = 0, val = 0, result = 0;
|
|
int first = 1;
|
|
int count = 1;
|
|
|
|
memset(line, 0, LINE_SIZE);
|
|
r = fgets(line, LINE_SIZE, stdin);
|
|
|
|
if (r == NULL) {
|
|
printf("Nepodarilo sa nacitat hodnotu x.\n");
|
|
return 0;
|
|
}
|
|
assert(r != NULL);
|
|
x = strtod(line, &endptr);
|
|
char *p_check = line;
|
|
while (isspace((unsigned char)*p_check)) p_check++;
|
|
if (p_check == endptr) {
|
|
return 0;
|
|
}
|
|
while (fgets(line, LINE_SIZE, stdin) != NULL) {
|
|
if (strlen(line) <= 1 && (line[0] == '\n' || line[0] == '\r')) {
|
|
break;
|
|
}
|
|
char *ptr = line;
|
|
while (isspace((unsigned char)*ptr)) ptr++;
|
|
if (*ptr == '\0') break;
|
|
|
|
val = strtod(ptr, &endptr);
|
|
if (ptr == endptr) {
|
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", count);
|
|
return 0;
|
|
}
|
|
if (first) {
|
|
result = val;
|
|
first = 0;
|
|
} else {
|
|
result = result * x + val;
|
|
}
|
|
count++;
|
|
}
|
|
printf("Vysledok je: %.2f\n", result);
|
|
return 0;
|
|
} |