This commit is contained in:
Peter Sabol 2022-03-31 10:21:27 +02:00
parent afa3571727
commit 73a040fa6b

View File

@ -1,10 +1,24 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define LINE_SIZE 100
//#include<conio.h>
float program(float polynom[], float n, float k){
float result = 0;
for(int a = 0; a < k; a++){
result = result * n + polynom[a];
}
return result;
}
/*void main() {
int degree,x;
int coeff[10], i;
@ -37,9 +51,15 @@
*/
int main(){
int pole[LINE_SIZE];
int n=0;
char*vstup;
float pole[LINE_SIZE];
//double n;
float n;
int m;
int a=0;
int b=0;
memset(pole,0,LINE_SIZE*sizeof(float));
/*char*vstup;
char riadok[LINE_SIZE];
do {
vstup=fgets(riadok,LINE_SIZE,stdin);
@ -48,5 +68,45 @@ int main(){
//printf("%s",*vstup);
for(int i=0;n>i;i++){
printf("%s",vstup);
}*/
int p = scanf("%lf",&n);
if(1 != p){
return 1;
}
for(;b<LINE_SIZE){
b++;
char vel[50] ={0};
char* g =fgets(value,100,stdin);
if(a==0 && g==NULL) error == true;
bool error==false;
for (a < strlen(vel); a++) {
if (vel[a] != '\n' && vel[a] != ' ' && vel[a] != '.' && vel[a] != ',' && vel[a] != '-' && isdigit(vel[a]) == false) {
error = true; b++;break;}
}
if (error == true) {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", a);
exit(0);
}
if (g == NULL) {
break;
}
else if(vel[0] == '\n'){
if (b == 0) {
b--;
continue;
}
else break;
}
else if (vel[0] == EOF) break;
pole[b] = atof(value);
}
float k = b;
printf("Vysledok je: %.2f\n", program(pole, n, k));
return 0;
}