cv3
This commit is contained in:
parent
f7ad89efe0
commit
cef61faf0c
@ -1,6 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_LINE_LENGTH 256
|
||||
@ -14,32 +13,25 @@ bool IsValidNumber(const char *line) {
|
||||
int main() {
|
||||
char line[MAX_LINE_LENGTH];
|
||||
double result = 0;
|
||||
int exponent = 2;
|
||||
double x;
|
||||
|
||||
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
|
||||
printf("Nepodarilo sa nacitat zaklad x\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
double x = strtod(line, NULL);
|
||||
result += 1;
|
||||
|
||||
while (1) {
|
||||
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
|
||||
if (line[0] == '\n') {
|
||||
break;
|
||||
}
|
||||
printf("Nepodarilo sa nacitat polynom\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
x = strtod(line, NULL);
|
||||
result = result * x + 1;
|
||||
|
||||
exponent--;
|
||||
while (fgets(line, MAX_LINE_LENGTH, stdin) != NULL && IsValidNumber(line)) {
|
||||
double coefficient = strtod(line, NULL);
|
||||
result = result * x + coefficient;
|
||||
}
|
||||
|
||||
if (line[0] != '\n') {
|
||||
printf("Nepodarilo sa nacitat koeficient polynomu\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Vysledok je: %.2f\n", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user