title: Calculating a Percentile
body: <p>I need a little program which:</p>
  
  <ol>
  <li>Reads natural number n</li>
  <li>then reads n real numbers r0,r1,r2,...,rn</li>
  <li>then reads another real number x</li>
  </ol>
  
  <p>And then prints the size of x in percentiles in relation to the numbers r0,r1,r2,...,rn</p>
  
  <pre><code>    #include&lt;stdio.h&gt;
  
  
  int main(){
  
  int n, i=0;
  double r[1000], x;
  
  printf("Enter how many numbers\n");
  scanf("%i", &amp;n);
  
  printf("Enter numbers\n");
  while(i&lt;n){
      scanf("%lf", &amp;r[i]);
      i++;
      }
  
  printf("Enter x:\n");
  scanf("%lf", &amp;x);
  // need part here
  // where percentiles are calculated
  
  }
  </code></pre>
  
  <p>So here is my problem, how the hell i can calculate that percentiles?
  I've read a lot of about percentiles and still I don't understand that, so maybe someone will explain it to me what i need to do, or just show me a pattern how to calculate that percentiles.
  I know C language a bit so i can write alone if some1 explain it to me how i can calculate percentiles ;o</p>
  
  <p>P.S. about percentiles from wikipedia </p>
  
  <p>In statistics, a percentile (or centile) is the value of a variable below which
   a certain percent of observations fall. For example, the 20th percentile is the value (or score) below 
  which 20 percent of the observations may be found.
  The 25th percentile is also known as the first quartile (Q1), the 50th percentile as the median or second quartile (Q2), and the 75th percentile as the third quartile (Q3).</p>
  
  <p>EDIT: Okay everything works (I think), but i have 1 more question:
  My code looks that</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  void sortowanie( double r[1000], int n){
      int i,j;
      double temp;
      for(i=0; i&lt;n; i++)
          for(j=0;j&lt;n-1; j++){
              if (r[j]&gt;r[j+1]){
                  temp=r[j+1];
                  r[j+1]=r[j];
                  r[j]=temp;
                  }
  
              }
  }
  
  int centyl(double x, int n){
  int temp, wynik;
  temp=n-x;
  wynik=100*temp/n;
  return wynik;
  
  }
  
  
  int main(){
  
  int n, i=0;
  double r[1000], x;
  
  printf("Enter how many numbers\n");
  scanf("%i", &amp;n);
  
  printf("Enter numbers\n");
  while(i&lt;n){
      scanf("%lf", &amp;r[i]);
      i++;
      }
  
  printf("Enter x:\n");
  scanf("%lf", &amp;x);
  
  sortowanie(r, n);
  
  printf("Centyl to %i\n", centyl(x, n) );
  
  return 0;
  }
  </code></pre>
  
  <p>And want to know what protection can I do to don't break that program?
  Are there any protections which I can make here? </p>