42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <ctype.h>
|
|
|
|
int main () {
|
|
char* input = (char*) calloc (100, sizeof(char));
|
|
double x;
|
|
char* ptr;
|
|
int counter = 0;
|
|
double numbers [100];
|
|
numbers[0] = 0;
|
|
for (int i = 0; fgets(input, 100, stdin) != NULL; i++){
|
|
if (!strcmp("\n", input))
|
|
break;
|
|
|
|
for(int j = 0; input[j] != '\0' && input[j] != '\n'; j++)
|
|
if(!isdigit(input[j]) && input[j] != '.'){
|
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n");
|
|
return 0;
|
|
}
|
|
if (i == 0){
|
|
x = (double)strtod(input, &ptr);
|
|
}
|
|
else {
|
|
numbers [i] = (double)strtod(input, &ptr);
|
|
}
|
|
counter = i;
|
|
}
|
|
double result = 0;
|
|
for(int i = 1; i <= counter; i++)
|
|
result += pow (x, i-1) * numbers [counter - i + 1];
|
|
|
|
result = roundf((float) result * 100)/100;
|
|
|
|
printf ("Vysledok je: ");
|
|
printf ("%.2f\n", result);
|
|
free(input);
|
|
return 0;
|
|
}
|