1
This commit is contained in:
parent
80403c694a
commit
e24c13ad36
40
du2/program.c
Normal file
40
du2/program.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_SIZE 100
|
||||
|
||||
int main(){
|
||||
char line[LINE_SIZE];
|
||||
float x;
|
||||
float coefficients[50];
|
||||
int count = 0;
|
||||
|
||||
if(fgets(line, LINE_SIZE, stdin) == NULL) {
|
||||
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
|
||||
return 1;
|
||||
}
|
||||
x = strtof(line, NULL);
|
||||
|
||||
while (fgets(line, LINE_SIZE, stdin) != NULL) {
|
||||
if (strlen(line) == 1)
|
||||
break;
|
||||
float coef = strtof(line, NULL);
|
||||
coefficients[count++] = coef;
|
||||
}
|
||||
|
||||
if(count == 0){
|
||||
printf("Chyba: Nepodarilo sa nacitat koeficienty.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
float result = coefficients[0];
|
||||
for (int i = 1; i < count; i++) {
|
||||
result = result * x + coefficients[i];
|
||||
}
|
||||
|
||||
printf("Vysledok je: %.2f\n", result);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user