pvjc23/du3/program.c

61 lines
1.1 KiB
C

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define VELKOST_POLA 50
int main(){
char rip[SIZE];
memset(rip, '\0', SIZE*sizeof(char));
int a = 0;
for(int b = 0; 1; b++){
a = getchar();
if(a == EOF || a == '')
break;
rip[b] = a;
}
for(int c = 0, d = 0; c < strlen(rip); c++){
if(rip[c] == '\n'){
d++;
}
else if((rip[c]<='10'&&rip[c]>='0') || (rip[c]=='.') || (rip[c]==EOF) || (rip[c]==''));
else if(d == 0){
printf("Nepodarilo sa nacitat zaklad x\n");
return 0;
}
else {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", d);
return 0;
}
}
int kofi = -1;
for(int c = 0; c < strlen(rip); c++){
if(rip[c] == '\n')
continue;
else for(int c2 = 0; rip[c]!='\n'; c++; c2++);
kofi++;
}
long double x = 0;
char *finish = NULL;
char *start = rip;
x = strtof(start, &finish);
start = finish;
long double n = 0;
for(int c = 0; c < kofi; c++){
long double d = 1; f = 0;
f = strtof(start, &finish);
start = finish;
d = dop(x,(kofi-c)-1);
n+ = d*f;
}
n = round(n*100)/100;
printf("Vysledok je: %.2Lf\n", n);
return STOP;
}