Aktualizovat du1/program.c
This commit is contained in:
parent
b928f90e63
commit
5cd4521951
124
du1/program.c
124
du1/program.c
@ -1,37 +1,107 @@
|
|||||||
#include <assert.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
int main() {
|
#include <string.h>
|
||||||
return 0;
|
#include <ctype.h>
|
||||||
char riadok[LINE_SIZE];
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define LINE_SIZE 128
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
double vysledok = 0;
|
||||||
|
int poradie = 0;
|
||||||
|
|
||||||
|
char riadok[LINE_SIZE];
|
||||||
memset(riadok, 0,LINE_SIZE);
|
memset(riadok, 0,LINE_SIZE);
|
||||||
|
|
||||||
//zaciatok riadku - resp. zaciatocne pismeno
|
|
||||||
char* r = fgets(riadok,LINE_SIZE,stdin);
|
char* r = fgets(riadok,LINE_SIZE,stdin);
|
||||||
|
|
||||||
if (r == NULL) { exit(EXIT_FAILURE); }
|
if (r == NULL)
|
||||||
|
|
||||||
while (r != '\0' || r != EOF)
|
|
||||||
{
|
{
|
||||||
if (r == ' ') {break;}
|
printf("Chyba: Zlyhalo nacitvanaie vstupu.\n");
|
||||||
r++;
|
exit(1);
|
||||||
if ()
|
}
|
||||||
}#include <assert.h>
|
|
||||||
#include <stdio.h>
|
double x;
|
||||||
int main() {
|
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;
|
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); }
|
// #include <assert.h>
|
||||||
|
// #include <stdio.h>
|
||||||
|
// int main() {
|
||||||
|
// return 0;
|
||||||
|
// char riadok[LINE_SIZE];
|
||||||
|
|
||||||
|
// memset(riadok, 0,LINE_SIZE);
|
||||||
|
|
||||||
while (r != '\0' || r != EOF)
|
// //zaciatok riadku - resp. zaciatocne pismeno
|
||||||
{
|
// char* r = fgets(riadok,LINE_SIZE,stdin);
|
||||||
if (r == ' ') {break;}
|
|
||||||
r++;
|
// if (r == NULL) { exit(EXIT_FAILURE); }
|
||||||
if ()
|
|
||||||
}
|
// 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 ()
|
||||||
|
// }
|
||||||
Loading…
Reference in New Issue
Block a user