#include #include //for the iomanipulator setw ("set width") #include using namespace std; //Sort the 2021 median household income for each state in increasing order. //https://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_income int main() { int a[] { 53913, //Alabama 77845, //Alaska 69056, //Arizona 52528, //Arkansas 84907, //California 82254, //Colorado 83771, //Connecticut 71091, //Delaware 63062, //Florida 66559, //Georgia 84857, //Hawaii 66474, //Idaho 72205, //Illinois 62743, //Indiana 65600, //Iowa 64124, //Kansas 55573, //Kentucky 52087, //Louisiana 64767, //Maine 90203, //Maryland 89645, //Massachusetts 63498, //Michigan 77720, //Minnesota 48716, //Mississippi 61847, //Missouri 63249, //Montana 66817, //Nebraska 66274, //Nevada 88465, //New Hampshire 89296, //New Jersey 53992, //New Mexico 74314, //New York 61972, //North Carolina 66519, //North Dakota 62262, //Ohio 55826, //Oklahoma 71562, //Oregon 68957, //Pennsylvania 74008, //Rhode Island 59318, //South Carolina 66143, //South Dakota 59695, //Tennessee 66962, //Texas 79449, //Utah 72431, //Vermont 80963, //Virginia 84247, //Washington 51248, //West Virginia 67125, //Wisconsin 65204 //Wyoming }; int n {size(a)}; //the number of elements in the array for (int i {n - 1}; i > 0; --i) { for (int j {0}; j < i; ++j) { //a[j] should be less than or equal to a[j+1]. //If a[j] and a[j+1] are in the wrong order, if (a[j] > a[j + 1]) { //Swap the values of a[j] and a[j+1]. int temp {a[j]}; a[j] = a[j + 1]; a[j + 1] = temp; } } //At this point, the value in a[i] is in the correct place. } for (int i {0}; i < n; ++i) { cout << setw(2) << i+1 << " " << a[i] << "\n"; } return EXIT_SUCCESS; }