commit
This commit is contained in:
parent
75a3b1c4dc
commit
3e96d3a32c
@ -2,45 +2,51 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#define LINE_SIZE 1024
|
#define LINE_SIZE 1024
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char line[LINE_SIZE];
|
char line[LINE_SIZE];
|
||||||
char* endptr = NULL;
|
char* endptr = NULL;
|
||||||
char* start = NULL;
|
char* r = NULL;
|
||||||
|
double x = 0, val = 0, result = 0;
|
||||||
memset(line, 0, LINE_SIZE);
|
|
||||||
char* r1 = fgets(line, LINE_SIZE, stdin);
|
|
||||||
assert(r1 != NULL);
|
|
||||||
|
|
||||||
double x = strtod(line, NULL);
|
|
||||||
|
|
||||||
memset(line, 0, LINE_SIZE);
|
|
||||||
char* r2 = fgets(line, LINE_SIZE, stdin);
|
|
||||||
assert(r2 != NULL);
|
|
||||||
|
|
||||||
int len = strlen(line);
|
|
||||||
start = line;
|
|
||||||
|
|
||||||
double result = 0.0;
|
|
||||||
int first = 1;
|
int first = 1;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
while (start < (line + len)) {
|
memset(line, 0, LINE_SIZE);
|
||||||
double val = strtod(start, &endptr);
|
r = fgets(line, LINE_SIZE, stdin);
|
||||||
|
|
||||||
if (start != endptr) {
|
if (r == NULL) {
|
||||||
|
printf("Nepodarilo sa nacitat hodnotu x.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
assert(r != NULL);
|
||||||
|
x = strtod(line, &endptr);
|
||||||
|
if (line == endptr) {
|
||||||
|
printf("Nepodarilo sa nacitat hodnotu x.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
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(line, &endptr);
|
||||||
|
if (line == endptr) {
|
||||||
|
printf("Nepodarilo sa nacitat koeficient %d.\n", count);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
result = val;
|
result = val;
|
||||||
first = 0;
|
first = 0;
|
||||||
} else {
|
} else {
|
||||||
result = result * x + val;
|
result = result * x + val;
|
||||||
}
|
}
|
||||||
start = endptr;
|
count++;
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
printf("Vysledok je: %.2f\n", result);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user