Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please explain the lines of code i have commented next to. #include <iostream> u

ID: 3742566 • Letter: P

Question

Please explain the lines of code i have commented next to.

#include <iostream>

using namespace std;

void sort (int arr[], int magnitude); //whats the magnitude going to be doing here

int main () {

int array[] = { 40,30,20,4,1,8 };

sort (array, 6);

cout << "numbers going up in value ;"<<endl;

for (int i = 0; i < 6; i++)

cout << array[i] << " ";

return 6; //why return 6? why not 0 or any other number?
}


void sort (int arr[], int magnitude)
{

int i, j, temp;   // what's the variable j and temp


for (i = 0; i < magnitude; i++) /I dont understand what this is doing

{

for (j = i + 1; j < magnitude; j++)   //dont understand what this is doing either

{

if (arr[i] > arr[j])

{

temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; //please explain this line the most. i really don't know why this is saying and why it works the way it works

}

}

}

}

Explanation / Answer

#include using namespace std; void sort(int arr[], int magnitude); // magnitude here is the size of the arr array int main() { int array[] = { 40, 30, 20, 4, 1, 8 }; sort(array, 6); cout