This commit is contained in:
kr820js 2024-03-03 16:47:37 +01:00
parent 91b75ab357
commit c31d5eef70

View File

@ -7,31 +7,27 @@
int main() int main()
{ {
float result_of_main; float result_of_main=0;
float x,a,b,c; float array_of_numbers[SIZE_OF_ARRAY];
int result=reading_input(&x); int counter=0;
int result;
while(1){
float x=0;
result=reading_input(&x);
if(result==0||result==2){
break;
}
array_of_numbers[counter]=x;
counter++;
}
if(result==0){ if(result==0){
printf("x");
return 0; return 0;
} }
result=reading_input(&a); for(int j=1; j<counter; j++){
if(result==0){ result_of_main=result_of_main+array_of_numbers[j]*pow(array_of_numbers[0],(counter-j)-1);
printf("a");
return 0;
} }
result=reading_input(&b);
if(result==0){
printf("b");
return 0;
}
result=reading_input(&c);
if(result==0){
printf("c");
return 0;
}
result_of_main=a*(x*x)+b*x+c;
printf("Vysledok je: %.2f\n", result_of_main); printf("Vysledok je: %.2f", result_of_main);
return 0; return 0;
} }
int reading_input(float *number){ int reading_input(float *number){
@ -41,7 +37,7 @@ int reading_input(float *number){
if (buffer[j]>='0'&&buffer[j]<='9') { if (buffer[j]>='0'&&buffer[j]<='9') {
continue; continue;
} }
if (buffer[j]=='.'||buffer) { if (buffer[j]=='.') {
continue; continue;
} }
if(buffer[j]=='\n'){ if(buffer[j]=='\n'){
@ -51,7 +47,9 @@ int reading_input(float *number){
printf("You have entered wrong number.\n"); printf("You have entered wrong number.\n");
return 0; return 0;
} }
if(buffer[0]=='\0'){
return 2;
}
*number=atof(buffer); *number=atof(buffer);
return 1; return 1;
} }