diff options
Diffstat (limited to 'src/c/statisticsFunctions/median/dmediana.c')
-rw-r--r-- | src/c/statisticsFunctions/median/dmediana.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/c/statisticsFunctions/median/dmediana.c b/src/c/statisticsFunctions/median/dmediana.c index cb2463c..8b37fd1 100644 --- a/src/c/statisticsFunctions/median/dmediana.c +++ b/src/c/statisticsFunctions/median/dmediana.c @@ -17,7 +17,9 @@ double dmediana(double *in, int size) { - double a; double fin; + double a; double fin; double in_copy[size]; +for(int i=0; i< size; i++) + in_copy[i]= in[i]; for (int i = 0; i < size; ++i) @@ -28,15 +30,15 @@ double dmediana(double *in, int size) { - if (in[i] > in[j]) + if (in_copy[i] > in_copy[j]) { - a = in[i]; + a = in_copy[i]; - in[i] = in[j]; + in_copy[i] = in_copy[j]; - in[j] = a; + in_copy[j] = a; } @@ -47,11 +49,11 @@ double dmediana(double *in, int size) if(size%2 ==0) { - fin= (in[size/2]+ in[(size/2)-1])/2; + fin= (in_copy[size/2]+ in_copy[(size/2)-1])/2; } else { - fin= in[(size-1)/2]; + fin= in_copy[(size-1)/2]; } return fin; |