Изменить 'a1/program.c'
This commit is contained in:
parent
940117cb91
commit
e777fc6e7e
12
a1/program.c
12
a1/program.c
@ -5,26 +5,28 @@
|
||||
|
||||
int main () {
|
||||
char* input = (char*) calloc (100, sizeof(char));
|
||||
int x;
|
||||
double x;
|
||||
char* ptr;
|
||||
int counter = 0;
|
||||
int numbers [100];
|
||||
double numbers [100];
|
||||
numbers[0] = 0;
|
||||
for (int i = 0; fgets(input, 100, stdin) != NULL; i++){
|
||||
if (!strcmp("\n", input))
|
||||
break;
|
||||
|
||||
if (i == 0){
|
||||
x = (int)strtol(input, &ptr, 10);
|
||||
x = (double)strtod(input, &ptr, 10);
|
||||
}
|
||||
else {
|
||||
numbers [i] = (int)strtol(input, &ptr, 10);
|
||||
numbers [i] = (double)strtod(input, &ptr, 10);
|
||||
}
|
||||
counter = i;
|
||||
}
|
||||
double result = 0;
|
||||
for(int i = 1; i <= counter; i++)
|
||||
result += (int)pow (x, i-1) * numbers [counter - i + 1];
|
||||
result += pow (x, i-1) * numbers [counter - i + 1];
|
||||
|
||||
result = roundf((float) result * 100)/100;
|
||||
|
||||
printf ("Vysledok je: ");
|
||||
printf ("%.2f\n", result);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user