pvjc24/cv3/program.c

34 lines
851 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define LENGTH 256
int main(){
char line[LENGTH];
char *y, *chcf;
int cfIdx, cf1, y1,x1,chcf1 = 0;
double x, cf,result = 0;
fgets(line, 100, stdin);
y = strtok(line,"\n");
x = strtod(line, NULL);
y1 = *y;
if(y1 >= 'A' && line[0] != '\n'){
printf("Nepodarilo sa nacitat zaklad x\n");
return 1;
}
while(line[0] != '\n'){
cfIdx++;
result = result * x + cf;
fgets(line, 100, stdin);
chcf = strtok(line,"\n");
cf = strtod(line,NULL);
chcf1 = *chcf;
if(chcf1 >='A' && line[0] != '\n'){
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", cfIdx);
return 1;
}
}
printf("Vysledok je: %.2f\n", result);
return 0;
}