This commit is contained in:
Džubara 2024-02-28 15:58:29 +01:00
parent 0bff677e4f
commit 13a514d406

View File

@ -14,8 +14,7 @@ bool IsValidNumber(const char *line) {
int main() { int main() {
char line[MAX_LINE_LENGTH]; char line[MAX_LINE_LENGTH];
double result = 0; double result = 0;
int exponent = 2; int exponent = 2;
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) { if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
printf("Nepodarilo sa nacitat zaklad x\n"); printf("Nepodarilo sa nacitat zaklad x\n");
@ -23,7 +22,7 @@ int main() {
} }
double x = strtod(line, NULL); double x = strtod(line, NULL);
result += x; result += 1;
while (1) { while (1) {
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) { if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
@ -35,9 +34,9 @@ int main() {
} }
x = strtod(line, NULL); x = strtod(line, NULL);
result += x * exponent; result = result * x + 1;
exponent--; exponent--;
} }
printf("Vysledok je: %.2f\n", result); printf("Vysledok je: %.2f\n", result);