int b[] = {11, 7, 3, 99, 113};
const int sizeOFarray = sizeof(b) / sizeof(b[0]); // Calculating the size of the array
int C[5]; // Array to hold the sorted values
int indices[5]; // Array to hold the original indices
void setup()
{
Serial.begin(9600);
// Copying original array to C and storing the original indices
for (int i = 0; i < sizeOFarray; i++)
{
C[i] = b[i];
indices[i] = i; // To store the original index
}
// Bubble Sorting array C in ascending order based on value
for (int i = 0; i < sizeOFarray - 1; i++)
{
for (int j = 0; j < sizeOFarray - i - 1; j++)
{
if (C[j] < C[j + 1])
{
// Swaping values in C
int tempValue = C[j];
C[j] = C[j + 1];
C[j + 1] = tempValue;
// Swap corresponding indices
int tempIndex = indices[j];
indices[j] = indices[j + 1];
indices[j + 1] = tempIndex;
}
}
}
// Printing sorted array with original indices
for (int i = 0; i < sizeOFarray; i++)
{
Serial.print(i + 1); // Position from 1 to 5
Serial.print(") C[");
Serial.print(indices[i]); // Original index
Serial.print("]=");
Serial.println(C[i]); // Sorted value
}
}
void loop() {}