This commit is contained in:
kr820js 2024-03-03 18:24:19 +01:00
parent 0fa3a58d5c
commit ba6dfb22e2

View File

@ -3,9 +3,6 @@
#include <math.h> #include <math.h>
#define SIZE_OF_ARRAY 100 #define SIZE_OF_ARRAY 100
#define LINE_SIZE 2
double powering(double, int);
int main() int main()
{ {
@ -32,19 +29,17 @@ int main()
return 0; return 0;
} }
for(int j=1; j<counter; j++){ for(int j=1; j<counter; j++){
double true_power=powering(array_of_numbers[0],(counter-j)-1); result_of_main += array_of_numbers[j]*pow(array_of_numbers[0],(counter-j)-1);
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;
} }
int reading_input(double *number){ int reading_input(double *number){
char buffer[SIZE_OF_ARRAY]; char buffer[SIZE_OF_ARRAY];
char *fgets_result = fgets(buffer,SIZE_OF_ARRAY,stdin); if(fgets(buffer,SIZE_OF_ARRAY,stdin)==NULL){
if(fgets_result==NULL){
return 2; return 2;
} }
for(int j=0; buffer[j]!='\0'; j++){ for(int j=0; buffer[j]!='\0'; j++){
if (buffer[j]>='0'&&buffer[j]<='9') { if (buffer[j]>='0'&&buffer[j]<='9') {
continue; continue;
@ -65,11 +60,5 @@ int reading_input(double *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;
}