This commit is contained in:
Roman Khaliavka 2025-03-06 12:59:38 +00:00
parent 71dc0bce6f
commit 04f0e849eb

46
du2/program.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LINE_SIZE 100
int read_double(double *num){
char line[LINE_SIZE];
if(!fgets(line, LINE_SIZE, stdin)){
return 0;
}
char *endptr;
*num = strtod(line, &endptr);
if(endptr == line || (*endptr != '\0' && *endptr != '\n')){
return 0;
}
return 1;
}
int main(){
double x, coef, result = 0.0;
int coef_index = 0;
if(!read_double(&x)){
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
return 1;
}
while(read_double(&coef)){
if(coef_index == 0){
result = coef;
}else{
result = result * x + coef;
}
coef_index++;
}
if(coef_index == 0){
printf("Chyba: Nepodarilo sa nacitat ziadne koeficienty.\n");
return 1;
}
printf("Vysledok je: %.2f\n", round(result * 100) / 100);
return 0;
}