I'm trying to show a ranking list of my array qt, which contains 5 numbers.
int i, j;
int qt[5] = {10,20,10,50,20};
int tempqt;
for (i=0; i<5; i++)
{
for(j=(i+1); j<5; j++)
{
if (qt[i] >= qt[j])
{
tempqt = qt[i];
qt[i] = qt[j];
qt[j] = tempqt;
}
}
}
for(i=0; i<5; i++)
{
cout << i+1 << ".number: " << qt[i] << endl;
}
normally, the 2 for-loops sort my array and the last for-loop displays my array ordered, so it looks like this:
- 1.number: 10
- 2.number: 10
- 3.number: 20
- 4.number: 20
- 5.number: 50
But I want to display the numbers with the same value as the same ranking position, so like this:
- 1.number: 10
- 1.number: 10
- 2.number: 20
- 2.number: 20
- 3.number: 50