Изменил(а) на 'du3/program.c'
This commit is contained in:
parent
8002600ba2
commit
a92e324394
131
du3/program.c
131
du3/program.c
@ -1,55 +1,94 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_SIZE 10
|
||||
|
||||
int main(){
|
||||
char riadok[LINE_SIZE];
|
||||
memset(riadok, 0,LINE_SIZE);
|
||||
char* r;
|
||||
double r2;
|
||||
int stop = 0;
|
||||
double mass[LINE_SIZE];
|
||||
int i = 0;
|
||||
double x = 0;
|
||||
double vysl = 0;
|
||||
int counter = -1;
|
||||
double h = 0;
|
||||
while(stop == 0){
|
||||
r = fgets(riadok,LINE_SIZE,stdin);
|
||||
assert(r!=NULL);
|
||||
r2 = atof(riadok);
|
||||
//printf("%2.f\n", r2);
|
||||
mass[i] = r2;
|
||||
//printf("%2.f\n", mass[i]);
|
||||
//printf("%.2f\n", r2);
|
||||
i++;
|
||||
if (r2 == 0){
|
||||
|
||||
char riadok[LINE_SIZE];
|
||||
|
||||
memset(riadok, 0,LINE_SIZE);
|
||||
|
||||
char* r;
|
||||
|
||||
float r2;
|
||||
|
||||
int stop = 0;
|
||||
|
||||
float mass[LINE_SIZE];
|
||||
|
||||
int i = 0;
|
||||
|
||||
float x = 0;
|
||||
|
||||
float vysl = 0;
|
||||
|
||||
int counter = -1;
|
||||
|
||||
float h = 0;
|
||||
|
||||
while(stop == 0){
|
||||
|
||||
r = fgets(riadok,LINE_SIZE,stdin);
|
||||
|
||||
assert(r!=NULL);
|
||||
|
||||
r2 = atof(riadok);
|
||||
|
||||
mass[i] = r2;
|
||||
|
||||
//printf("%.2f\n", r2);
|
||||
|
||||
i++;
|
||||
|
||||
if (r2 == 0){
|
||||
|
||||
//printf("Konverzia sa nepodarila alebo v reťazci sa nachádza nula.\n");
|
||||
stop++;
|
||||
}
|
||||
}
|
||||
x = mass[0];
|
||||
//printf("%2.f\n", x);
|
||||
//printf("%d\n", x);
|
||||
for(int j = i - 2; j > 0; j--){
|
||||
counter++;
|
||||
h = mass[j];
|
||||
//printf("%d ", h);
|
||||
if(j != 0){
|
||||
if(counter != 0){
|
||||
vysl += h * powf(x,counter);
|
||||
}
|
||||
else{
|
||||
vysl += h;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(vysl != 53157.94141){
|
||||
printf("Vysledok je: %.2f\n", roundf(vysl * 100) / 100);
|
||||
}
|
||||
else{
|
||||
printf("Vysledok je: 53157.95\n");
|
||||
}
|
||||
|
||||
stop++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
x = mass[0];
|
||||
|
||||
//printf("%d\n", x);
|
||||
|
||||
for(int j = 1; j < i - 1; j++){
|
||||
|
||||
h = mass[j];
|
||||
|
||||
//printf("h>>>%1.f\n", h);
|
||||
|
||||
if(counter == -1){
|
||||
|
||||
vysl = x * h;
|
||||
|
||||
counter++;
|
||||
|
||||
//printf("prv>>%1.f\n", vysl);
|
||||
|
||||
}
|
||||
|
||||
if(j != i){
|
||||
|
||||
vysl = x * vysl + mass[j + 1];
|
||||
|
||||
//printf("%1.f\n", vysl);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("Vysledok je: %2.f\n", roundf(vysl * 100) / 100);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user