2025-03-06 10:21:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define LINE_SIZE 100
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
char riadok[LINE_SIZE];
|
|
|
|
memset(riadok, 0, LINE_SIZE);
|
2025-03-06 10:36:49 +00:00
|
|
|
double sum = 0.0;
|
|
|
|
|
|
|
|
printf("Zadajte čísla: \n");
|
|
|
|
|
|
|
|
while (fgets(riadok, LINE_SIZE, stdin) != NULL) {
|
|
|
|
size_t len = strlen(riadok);
|
|
|
|
if (len > 0 && riadok[len - 1] == '\n') {
|
|
|
|
riadok[len - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(riadok) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* endptr = NULL;
|
|
|
|
double cislo = strtod(riadok, &endptr);
|
2025-03-06 10:21:11 +00:00
|
|
|
|
2025-03-06 10:36:49 +00:00
|
|
|
if (*endptr != '\0') {
|
|
|
|
printf("Neplatný vstup! Prosím, zadávajte iba čísla.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sum += cislo;
|
2025-03-06 10:21:11 +00:00
|
|
|
}
|
2025-03-06 10:36:49 +00:00
|
|
|
|
|
|
|
printf("Vysledok je: %.2f\n", sum);
|
2025-03-06 10:21:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|