This commit is contained in:
kr820js 2024-03-03 18:04:51 +01:00
parent a97de0454e
commit d90e55dcdb

View File

@ -5,15 +5,17 @@
#define SIZE_OF_ARRAY 100 #define SIZE_OF_ARRAY 100
#define LINE_SIZE 2 #define LINE_SIZE 2
double powering(double, int);
int main() int main()
{ {
float result_of_main=0; double result_of_main=0;
float array_of_numbers[SIZE_OF_ARRAY]; double array_of_numbers[SIZE_OF_ARRAY];
int counter=0; int counter=0;
int result; int result;
float pow_result; double pow_result;
while(1){ while(1){
float x=0; double x=0;
result=reading_input(&x); result=reading_input(&x);
if(result==0||result==2){ if(result==0||result==2){
break; break;
@ -25,18 +27,18 @@ int main()
return 0; return 0;
} }
for(int j=1; j<counter; j++){ for(int j=1; j<counter; j++){
float rawPow = pow(array_of_numbers[0],(counter-j)-1); //double rawPow = pow(array_of_numbers[0],(counter-j)-1);
float roundedPos = round(rawPow*100)/100; //double roundedPos = round(rawPow*100)/100;
//printf("RAW: %f, ROUNDED: %f\n", rawPow, roundedPos); double true_power=powering(array_of_numbers[0],(counter-j)-1);
// printf("RAW: %f, ROUNDED: %f, true %f\n", rawPow, roundedPos,true_power);
result_of_main += array_of_numbers[j]*rawPow;
}
result_of_main += array_of_numbers[j]*true_power;
}
printf("Vysledok je: %.2f\n",round(result_of_main * 100) / 100); printf("Vysledok je: %.2f\n",round(result_of_main * 100) / 100);
return 0; return 0;
} }
//ceil(result_of_main * 100) / 100) //ceil(result_of_main * 100) / 100)
int reading_input(float *number){ int reading_input(double *number){
char buffer[SIZE_OF_ARRAY]; char buffer[SIZE_OF_ARRAY];
fgets(buffer,SIZE_OF_ARRAY,stdin); fgets(buffer,SIZE_OF_ARRAY,stdin);
for(int j=0; buffer[j]!='\0'; j++){ for(int j=0; buffer[j]!='\0'; j++){
@ -59,4 +61,11 @@ int reading_input(float *number){
*number=atof(buffer); *number=atof(buffer);
return 1; return 1;
} }
double powering(double number, int counter){
double result=1;
for(int i=0; i<counter; i++){
result =result * number;
}
return result;
}