I need a little program which:
- Reads natural number n
- then reads n real numbers r0,r1,r2,…,rn
- then reads another real number x
And then prints the size of x in percentiles in relation to the numbers r0,r1,r2,…,rn
#include<stdio.h>
int main(){
int n, i=0;
double r[1000], x;
printf("Enter how many numbers\n");
scanf("%i", &n);
printf("Enter numbers\n");
while(i<n){
scanf("%lf", &r[i]);
i++;
}
printf("Enter x:\n");
scanf("%lf", &x);
// need part here
// where percentiles are calculated
}
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.S. about percentiles from wikipedia
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).
EDIT: Okay everything works (I think), but i have 1 more question:
My code looks that
#include<stdio.h>
void sortowanie( double r[1000], int n){
int i,j;
double temp;
for(i=0; i<n; i++)
for(j=0;j<n-1; j++){
if (r[j]>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", &n);
printf("Enter numbers\n");
while(i<n){
scanf("%lf", &r[i]);
i++;
}
printf("Enter x:\n");
scanf("%lf", &x);
sortowanie(r, n);
printf("Centyl to %i\n", centyl(x, n) );
return 0;
}
And want to know what protection can I do to don’t break that program?
Are there any protections which I can make here?
This is more math related and more appropriate for the Mathematics forum. However, I’ll save you the trouble since the thread is already here.
To find the percentile of anything just consider the following:
If you came 25th out of class of 200 students, then you did better than 175 of them. To find your percentile, you would divide the number of students you did better than by the total number of students.
For example:
That’s a very simplified way to find the percentile – it’s easy to understand and always works. I hope this helps you.