82 lines
1.3 KiB
C
82 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <ctype.h>
|
|
|
|
#define POLE 100
|
|
|
|
int main() {
|
|
|
|
double X = 0.00;
|
|
char vstup[POLE];
|
|
memset(vstup, 0,POLE); //osetrenie
|
|
char* a = fgets(vstup,POLE,stdin);
|
|
|
|
|
|
if (vstup[0] == '\n'){ //ked pride na enter
|
|
printf("koniec");
|
|
exit(0);
|
|
}
|
|
|
|
|
|
for (int i = 0; i < strlen(vstup)-1; i++){
|
|
//X = atof(riadok);
|
|
if(vstup[i] == '.'){
|
|
continue;
|
|
}
|
|
if (isdigit(vstup[i]) == 0){
|
|
printf ("neplati\n");
|
|
exit(0);
|
|
}
|
|
}
|
|
X = atof(a);
|
|
|
|
|
|
double polynom = 0.00;
|
|
char Ppole [POLE];
|
|
memset(Ppole, 0,POLE);
|
|
double rovnica [POLE];
|
|
int index = 0;
|
|
int stupen = 0;
|
|
double vysledok = 0.00;
|
|
int idx = 0;
|
|
|
|
while (1){
|
|
char* b = fgets(Ppole,POLE,stdin);
|
|
|
|
if (Ppole[0] == '\n'){ //ked pride na enter
|
|
break;
|
|
}
|
|
for (int i = 0; i < strlen(Ppole)-1; i++){
|
|
//X = atof(riadok);
|
|
if(Ppole[i] == '.'){
|
|
continue;
|
|
}
|
|
if (isdigit(Ppole[i]) == 0){
|
|
printf ("neplati\n");
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
polynom = atof (b);
|
|
rovnica[index] = polynom;
|
|
index++;
|
|
stupen++;
|
|
|
|
}
|
|
|
|
for (int i = stupen -1; i >= 0; i --){
|
|
vysledok = vysledok + rovnica[idx] * pow(X, i);
|
|
idx++;
|
|
}
|
|
|
|
|
|
vysledok = round (vysledok * 100)/100;
|
|
printf ("Vysledok je: %.2f\n", vysledok);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
} |