schema
This commit is contained in:
parent
d5d8deff25
commit
0bff677e4f
@ -13,8 +13,8 @@ bool IsValidNumber(const char *line) {
|
||||
|
||||
int main() {
|
||||
char line[MAX_LINE_LENGTH];
|
||||
double result = 1;
|
||||
int coefficientIndex = 0;
|
||||
double result = 0;
|
||||
int exponent = 2;
|
||||
|
||||
|
||||
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
|
||||
@ -22,24 +22,22 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
double x = strtod(line, NULL);
|
||||
result += x;
|
||||
|
||||
while (1) {
|
||||
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
|
||||
if (line[0] == '\n') {
|
||||
break;
|
||||
}
|
||||
printf("Nepodarilo sa nacitat polynom na %d mieste. \n", coefficientIndex);
|
||||
printf("Nepodarilo sa nacitat polynom\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *endPtr;
|
||||
double x = strtod(line, &endPtr);
|
||||
if (*endPtr != '\n' && *endPtr != '\0') {
|
||||
printf("Nespravny format cisla\n");
|
||||
return 1;
|
||||
}
|
||||
x = strtod(line, NULL);
|
||||
result += x * exponent;
|
||||
|
||||
result *= x;
|
||||
coefficientIndex++;
|
||||
exponent--;
|
||||
}
|
||||
|
||||
printf("Vysledok je: %.2f\n", result);
|
||||
|
Loading…
Reference in New Issue
Block a user