0

I need to find the first number that exceeds x[floor(0.8*N)+1], when there is duplicate values within the array. but am unsure how to do this. x refers to an array on integers which have been sorted in ascending order. Help is much appreciated.

void eightypercentile(int x[], values)
{
  int eightiethpercentile;
  if( x[floor(0.9*N)+1] <= x[floor(0.8*N)])
  {
    eightiethpercentile = /*first number that exceeds x[floor(0.8*N)+1] */
  }
  int eightiethpercentile = x[floor(0.8*N)+1];

}
Bharat
  • 2,960
  • 2
  • 38
  • 57
AkshaiShah
  • 5,739
  • 11
  • 37
  • 45
  • This discussion might be relevant: http://stackoverflow.com/questions/6553970/find-the-first-element-in-an-array-that-is-greater-than-the-target – Bharat Nov 15 '12 at 00:20
  • Is `values` the number of values in the array? (it better be...). – WhozCraig Nov 15 '12 at 01:12

1 Answers1

0

One way to do:

nc = ceil(N * 0.8)
nf = floor(N * 0.8)
if (nc == nf) nc++;
while (x[nc] == x[nc-1]) 
  nc++;
return x[nc];
perreal
  • 94,503
  • 21
  • 155
  • 181