2024-03-03 15:01:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define SIZE_OF_ARRAY 100
|
|
|
|
#define LINE_SIZE 2
|
|
|
|
|
2024-03-03 17:04:51 +00:00
|
|
|
double powering(double, int);
|
|
|
|
|
2024-03-03 15:01:11 +00:00
|
|
|
int main()
|
|
|
|
{
|
2024-03-03 17:04:51 +00:00
|
|
|
double result_of_main=0;
|
|
|
|
double array_of_numbers[SIZE_OF_ARRAY];
|
2024-03-03 15:47:37 +00:00
|
|
|
int counter=0;
|
|
|
|
int result;
|
2024-03-03 17:04:51 +00:00
|
|
|
double pow_result;
|
2024-03-03 15:47:37 +00:00
|
|
|
while(1){
|
2024-03-03 17:04:51 +00:00
|
|
|
double x=0;
|
2024-03-03 15:47:37 +00:00
|
|
|
result=reading_input(&x);
|
|
|
|
if(result==0||result==2){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
array_of_numbers[counter]=x;
|
|
|
|
counter++;
|
2024-03-03 15:01:11 +00:00
|
|
|
}
|
|
|
|
if(result==0){
|
2024-03-03 17:08:32 +00:00
|
|
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n",counter);
|
2024-03-03 15:01:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2024-03-03 15:47:37 +00:00
|
|
|
for(int j=1; j<counter; j++){
|
2024-03-03 17:04:51 +00:00
|
|
|
//double rawPow = pow(array_of_numbers[0],(counter-j)-1);
|
|
|
|
//double roundedPos = round(rawPow*100)/100;
|
|
|
|
double true_power=powering(array_of_numbers[0],(counter-j)-1);
|
|
|
|
// printf("RAW: %f, ROUNDED: %f, true %f\n", rawPow, roundedPos,true_power);
|
2024-03-03 16:40:44 +00:00
|
|
|
|
2024-03-03 17:04:51 +00:00
|
|
|
result_of_main += array_of_numbers[j]*true_power;
|
|
|
|
}
|
2024-03-03 16:41:49 +00:00
|
|
|
printf("Vysledok je: %.2f\n",round(result_of_main * 100) / 100);
|
2024-03-03 15:01:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2024-03-03 16:40:44 +00:00
|
|
|
//ceil(result_of_main * 100) / 100)
|
2024-03-03 17:04:51 +00:00
|
|
|
int reading_input(double *number){
|
2024-03-03 15:01:11 +00:00
|
|
|
char buffer[SIZE_OF_ARRAY];
|
|
|
|
fgets(buffer,SIZE_OF_ARRAY,stdin);
|
|
|
|
for(int j=0; buffer[j]!='\0'; j++){
|
|
|
|
if (buffer[j]>='0'&&buffer[j]<='9') {
|
|
|
|
continue;
|
|
|
|
}
|
2024-03-03 15:47:37 +00:00
|
|
|
if (buffer[j]=='.') {
|
2024-03-03 15:01:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(buffer[j]=='\n'){
|
|
|
|
buffer[j]='\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2024-03-03 15:47:37 +00:00
|
|
|
if(buffer[0]=='\0'){
|
|
|
|
return 2;
|
|
|
|
}
|
2024-03-03 15:01:11 +00:00
|
|
|
*number=atof(buffer);
|
|
|
|
return 1;
|
|
|
|
}
|
2024-03-03 17:04:51 +00:00
|
|
|
double powering(double number, int counter){
|
|
|
|
double result=1;
|
|
|
|
for(int i=0; i<counter; i++){
|
|
|
|
result =result * number;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2024-03-03 16:40:44 +00:00
|
|
|
|