Aktualizovat du1/program.c

This commit is contained in:
Tomáš Vlček 2026-03-04 18:58:32 +00:00
parent b928f90e63
commit 5cd4521951

View File

@ -1,37 +1,107 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
return 0;
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#define LINE_SIZE 128
int main()
{
double vysledok = 0;
int poradie = 0;
char riadok[LINE_SIZE];
memset(riadok, 0,LINE_SIZE);
//zaciatok riadku - resp. zaciatocne pismeno
char* r = fgets(riadok,LINE_SIZE,stdin);
if (r == NULL) { exit(EXIT_FAILURE); }
while (r != '\0' || r != EOF)
if (r == NULL)
{
if (r == ' ') {break;}
r++;
if ()
}#include <assert.h>
#include <stdio.h>
int main() {
return 0;
char riadok[LINE_SIZE];
memset(riadok, 0,LINE_SIZE);
//zaciatok riadku - resp. zaciatocne pismeno
char* r = fgets(riadok,LINE_SIZE,stdin);
if (r == NULL) { exit(EXIT_FAILURE); }
while (r != '\0' || r != EOF)
{
if (r == ' ') {break;}
r++;
if ()
printf("Chyba: Zlyhalo nacitvanaie vstupu.\n");
exit(1);
}
double x;
if (sscanf(riadok, "%lf", &x) != 1)
{
printf("Chyba: vstup NIE je cislom.\n");
exit(1);
}
bool trebaPrvyKoeficient = true;
//fgets vracia NULL, ak sa dostane na koniec suboru ('EOF' situsacia)
//boze moj, fgets() je vojnovy zlocin v ramci ludskej citatelnosti
while (fgets(riadok, LINE_SIZE, stdin) != NULL)
{
//ak konec riadku
if (riadok[0] == '\n')
{
break;
}
double koeficient;
poradie += 1;
if (sscanf(riadok, "%lf", &koeficient) == 1)
{
if (trebaPrvyKoeficient)
{
vysledok = koeficient;
trebaPrvyKoeficient = false;
}
else
{
vysledok = (vysledok * x) + koeficient;
}
}
else
{
printf("Chyba: Neplatny vstup v riadku č.%d\n", poradie);
exit(0);
}
}
printf("Vysledok je: %.2f\n", vysledok);
return 0;
}
// #include <assert.h>
// #include <stdio.h>
// int main() {
// return 0;
// char riadok[LINE_SIZE];
// memset(riadok, 0,LINE_SIZE);
// //zaciatok riadku - resp. zaciatocne pismeno
// char* r = fgets(riadok,LINE_SIZE,stdin);
// if (r == NULL) { exit(EXIT_FAILURE); }
// while (r != '\0' || r != EOF)
// {
// if (r == ' ') {break;}
// r++;
// if ()
// }#include <assert.h>
// #include <stdio.h>
// int main() {
// return 0;
// char riadok[LINE_SIZE];
// memset(riadok, 0,LINE_SIZE);
// //zaciatok riadku - resp. zaciatocne pismeno
// char* r = fgets(riadok,LINE_SIZE,stdin);
// if (r == NULL) { exit(EXIT_FAILURE); }
// while (r != '\0' || r != EOF)
// {
// if (r == ' ') {break;}
// r++;
// if ()
// }