This commit is contained in:
Jana Kapalková 2026-03-05 17:57:08 +01:00
parent 3143859bcb
commit 75a3b1c4dc

46
du1/program.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define LINE_SIZE 1024
int main() {
char line[LINE_SIZE];
char* endptr = NULL;
char* start = NULL;
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;
while (start < (line + len)) {
double val = strtod(start, &endptr);
if (start != endptr) {
if (first) {
result = val;
first = 0;
} else {
result = result * x + val;
}
start = endptr;
} else {
break;
}
}
return 0;
}