#include #include char names[] = {'a', 'b', 'c', 'd', 'e', 'f'}; int nFriends[] = {3, 5, 6, 2, 1, 2}; int main() { int i,j; for(i=0; i<3; i++) // Run selection sort for 3 iterations { int maxIndex=i; for(j=i; j<6; j++) { // find the maximum if(nFriends[j]>nFriends[maxIndex]) maxIndex=j; } // swap them int temp=nFriends[i]; nFriends[i] = nFriends[maxIndex]; nFriends[maxIndex] = temp; // also swap the names char t = names[i]; names[i] = names[maxIndex]; names[maxIndex]=t; printf("Person %c has %d friends.\n", names[i],nFriends[i]); } printf("\n"); system("pause"); }