Statistics › Moments ›
Rank
Calculates the rank of a number in a list of numbers.
Controller: CodeCogs
Contents
Interface
C++
Rank
template<class T> intrank( | int | x | |
int | n | ||
T* | data | ||
bool | ascending = true | ) |
Example 1
#include <codecogs/statistics/moments/rank.h> #include <iostream> int main() { double x[5] = {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.