/*---------------------------------------------------------- Elizabeth Sklar MC140.0X 8 November 2000 This program demonstrates manipulating arrays... ----------------------------------------------------------*/ #include #include #define SIZE 10 char states[SIZE][3] = { "FL","MI","TN","MO","WA","WI","MN","LA","AZ","CO" }; int votes[SIZE] = { 25, 18, 11, 11, 11, 11, 10, 9, 8, 8 }; char sorted_states[SIZE][3]; /*--------------------------------------------------------*/ /* print_states */ /* */ /* this function prints the abbreviations of the states */ /* in the argument "s", all on one line */ /* */ /*--------------------------------------------------------*/ void print_states( char s[][3] ) { int i; for ( i=0; i 0 ) { swap( sorted_states[i],sorted_states[i+1] ); } } printf( "after pass #%d ",pass ); print_states( sorted_states ); } } /* end of sort_states() */ /*--------------------------------------------------------*/ /* find_votes */ /* */ /* this function uses linear sort to find the entry in */ /* the "states" array that matches the "s" argument */ /* */ /* the function returns -1 if "s" is not found in the */ /* "states" array */ /* */ /* otherwise, the function returns the index in "states" */ /* of the entry that matches "s" */ /* */ /*--------------------------------------------------------*/ int find_votes( char s[] ) { int i = 0; while (( i < SIZE ) && ( strcmp( s,states[i] ) != 0 )) { i++; } if ( i == SIZE ) { return( -1 ); } else { return( i ); } } /* end of find_votes() */ /*--------------------------------------------------------*/ /* main program */ /* */ /*--------------------------------------------------------*/ void main() { int i, j; printf( "\nhere are the states:\n" ); print_states( states ); printf( "\nhere are the states and number of electoral votes:\n" ); print_votes(); mean_votes(); for ( i=0; i