112 lines
2.3 KiB
C
112 lines
2.3 KiB
C
#include <stdio.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;
|
|
int sum = 0;
|
|
|
|
// Getting the value of the variable
|
|
printf("\nEnter the value of x: ");
|
|
scanf("%d",&x);
|
|
|
|
// Getting the degreee of the polynomial
|
|
printf("\nEnter the degree of the polynomial: ");
|
|
scanf("%d",°ree);
|
|
|
|
// Getting the coefficients of all terms of the polynomial
|
|
printf("\nEnter the coeffients from lower order to higher order: \n");
|
|
for(i=0; i<=degree; i++) {
|
|
scanf("%d",&coeff[i]);
|
|
}
|
|
|
|
// Applying Horner's rule
|
|
sum = coeff[degree];
|
|
for(i=degree-1; i>=0; i--) {
|
|
sum = sum*x + coeff[i];
|
|
}
|
|
|
|
// Printing result
|
|
printf("\nResult: %d",sum);
|
|
}
|
|
|
|
*/
|
|
|
|
int main(){
|
|
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);
|
|
n++;
|
|
}while(*vstup!='\n');
|
|
//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;
|
|
} |