I have forgotten

• http://facebook.com/
• https://www.google.com/accounts/o8/id
• https://me.yahoo.com COST (GBP) 0.40 0.00 0

# Rank

Calculates the rank of a number in a list of numbers.
Controller: CodeCogs Contents  C++

## Rank

 template intrank( int x int n T* data bool ascending` = true` )
Returns the rank of a number in a list of numbers. The rank of a number is its size relative to other values in a list. (If you were to sort the list, the rank of the number would be its position.) Rank gives duplicate numbers the same rank. However, the presence of duplicate numbers affects the ranks of subsequent numbers. For example, in a list of integers sorted in ascending order, if the number 10 appears twice and has a rank of 5, then 11 would have a rank of 7 (no number would have a rank of 6).

### Example 1

```#include <codecogs/statistics/moments/rank.h>
#include <iostream>
int main()
{
double x = {4 , 5 , 8 , 6 , 3};
double rka = Stats::Moments::rank(4, 5, x);
double rkd = Stats::Moments::rank(4, 5, x, false);
std::cout << "The rank of 4 in the array x sorted in ascending order is: " << rka << std::endl;
std::cout << "The rank of 4 in the array x sorted in descending order is: " << rkd << std::endl;
return 0;
}```
Output:
```The rank of 4 in the array x sorted in ascending order is: 2
The rank of 4 in the array x sorted in descending order is: 4```

### Parameters

 x is the number whose rank you want to find n the size of the array data the actual array data ascending Default Value = true

### Returns

the rank of a number in a list of numbers

### Authors

Anca Filibiu (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.