Обновить du2/program.c
This commit is contained in:
parent
a95a2e3612
commit
345841f302
@ -3,10 +3,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define LINE_SIZE 100
|
#define LINE_SIZE 100 //maximalna veľkosť čiary
|
||||||
|
|
||||||
int read_double(double *value, int coef_index) {
|
int read_double(double *value, int coef_index) {
|
||||||
char line[LINE_SIZE];
|
char line[LINE_SIZE]; //deklaruje pole na uloženie reťazca
|
||||||
|
|
||||||
if (fgets(line, LINE_SIZE, stdin) == NULL) {
|
if (fgets(line, LINE_SIZE, stdin) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -20,8 +20,8 @@ int read_double(double *value, int coef_index) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *endptr;
|
char *endptr; // smernik na hľadanie konca reťazca pri prevode na číslo
|
||||||
*value = strtod(line, &endptr);
|
*value = strtod(line, &endptr); // Prevod reťazca na dvojité číslo
|
||||||
|
|
||||||
|
|
||||||
if (endptr == line || *endptr != '\0') {
|
if (endptr == line || *endptr != '\0') {
|
||||||
@ -39,13 +39,13 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double coef;
|
double coef; //uloženie koeficientu polynómu
|
||||||
double result = 0;
|
double result = 0; // uloženie výsledku
|
||||||
int coef_count = 0;
|
int coef_count = 0; //Počítadlo počtu zadaných koeficientov
|
||||||
|
|
||||||
while (1) {
|
while (1) { //Nekonečný cyklus na zadávanie koeficientov
|
||||||
coef_count++;
|
coef_count++;
|
||||||
int status = read_double(&coef, coef_count);
|
int status = read_double(&coef, coef_count); //Číta koeficient
|
||||||
|
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user