The easy O(n^2) answer is to use nested for-loops and increment a counter for every inversion
int counter = 0;
for(int i = 0; i < n - 1; i++)
{
for(int j = i+1; j < n; j++)
{
if( A[i] > A[j] )
{
counter++;
}
}
}
return counter;
Now I suppose you want a more efficient solution, I'll think about it.