/* Social Network (15 points) */ #include #include int main(void) { // PART A: int i,j; char names[] = {'a', 'b', 'c', 'd', 'e', 'f'}; int A[6][6] = { {0,1,0,0,0,0}, // Frendship relationships {1,0,1,1,0,0}, {0,1,0,1,0,0}, {0,1,1,0,1,1}, {0,0,0,1,0,0}, {0,0,0,1,0,0}}; int nFriends[6]; for(i=0; i<6; i++) nFriends[i]=0; for(i=0; i<6; i++) for(j=0; j<6; j++) nFriends[i] += A[i][j]; for(i=0; i<6; i++) printf("Person %c has %d friends.\n", names[i],nFriends[i]); // PART B: printf("\n\nTOP 3:\n"); 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"); }